Error in http-codec when GETting raw gist via coro-http
Parvulster opened this issue · 4 comments
When trying to to make an http request to get the raw contents of a gist, some strange behavior occurs. Making the request for the first time causes a successful connection, but no response is given back in the second variable. However, making the request again causes an "expected HTTP data" error from http-codec.
Looking further into the issue and printing the individual chunks being ran through by http-codec reveals what is causing the error. On the first run, the full response body appears to be received (still not sure why this isn't giving back the proper response variable). However, on the second run, the body of the response appears to be attached to the top of the HTTP response, causing the function to error trying to find the HTTP head, as it is not the first line that appears.
Normal Two Requests to Website
coroutine.wrap(function()
local status, response = http.request("GET", "https://google.com/")
print(1, response)
local status2, response2 = http.request("GET", "https://google.com/")
print(2, response2)
end)()
Prints
1 <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
2 <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>
Two Requests to Raw Gist
coroutine.wrap(function()
local status, response = http.request("GET", "https://gist.githubusercontent.com/Parvulster/6513bd4c240a30fd3cc15da2c3dda9d8/raw/5ac9f11a081083e639b01864432948dc59f2de99/Test")
print(1, response)
local status2, response2 = http.request("GET", "https://gist.githubusercontent.com/Parvulster/6513bd4c240a30fd3cc15da2c3dda9d8/raw/5ac9f11a081083e639b01864432948dc59f2de99/Test")
print(2, response2)
end)()
Prints
1
Uncaught Error: .../deps/coro-channel.lua:62: .../deps/http-codec.lua:193: expected HTTP data
stack traceback:
[C]: in function 'assert'
.../deps/coro-channel.lua:62: in function 'onPlain'
.../deps/secure-socket/biowrap.lua:76: in function <.../deps/secure-socket/biowrap.lua:61>
[C]: in function 'run'
[string "bundle:init.lua"]:52: in function <[string "bundle:init.lua"]:47>
[C]: in function 'xpcall'
[string "bundle:init.lua"]:47: in function 'fn'
[string "bundle:deps/require.lua"]:310: in function <[string "bundle:deps/require.lua"]:266>
I tested this on both Windows and a Linux VPS, with the same outcome on both.
Please let me know if you have any questions, and sorry for the messy issue report, I don't write these often.
Found the problem: http-codec
doesn't read the full header if it encounters a header line with no value. Will be fixed by #233.
The original file is at https://github.com/luvit/luvit/blob/master/deps/http-codec.lua. Should we change it there, too?
@Parvulster Were you able to test this with luvit's https module?
I was not.
Confirmed that it affects Luvit as well, will create a PR there too.