HTTP API corrupts request payload
viluon opened this issue ยท 1 comments
The HTTP API implementation reinterprets POST
payloads as text regardless of the binary setting. I ran into it when trying to POST
binary data to a server and getting garbage on the other side.
Also, the default headers are "Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
and "Accept-Charset": "UTF-8"
irrespective of the binary
flag.
Test with
local h = http.post {
url = "https://httpbin.org/anything",
body = string.rep("\254", 7),
binary = true,
}
local response = h.readAll()
h.close()
-- expected: 7
-- actual: 14
print(textutils.unserialiseJSON(response).headers["Content-Length"])
Or simply pastebin run uSfZyzi8
.
This issue concerns versions since at least v1.100.5 up to and including the latest v1.108.0, but the problematic code appeared with the http
rework as early as v1.81.0. It's possible that binary uploads never worked correctly in the first place.
Affected versions and flavours
Verified on CC:Tweaked 1.100.5 via copy-cat:
Verified by @tizu69 on Minecraft 1.18.2 / CC:Tweaked 1.101.3:
Verified on CC:Tweaked 1.103.1 via copy-cat:
Verified on CC:Tweaked 1.106.1 via CCEmuX 1.1.0:
Verified on CC:Tweaked 1.108.0 via eval.tweaked.cc: