Workaround LuaSocket's lax response validation
When receiving a HTTP response without a statusline, "nil" is returned as reponse headers and status line values, but the response code will still be "200 Success", which is quite not right as there wasn't ever a response status code received. This patch adds a check for a status line, and returns with an early error if needed. This condition can be triggered by trying to speak plain HTTP to a HTTPS-enabled server, e.g. using http://matrix.org:8448 instead of https://matrix.org:8448 as homeserver URL.
This commit is contained in:
@@ -65,7 +65,7 @@ function httpclient:request(log, method, url, query_args, body, headers)
|
|||||||
source = stringsource(body)
|
source = stringsource(body)
|
||||||
end
|
end
|
||||||
local result = {}
|
local result = {}
|
||||||
local r, c, h = make_request {
|
local r, c, h, statusline = make_request {
|
||||||
url = url,
|
url = url,
|
||||||
method = method,
|
method = method,
|
||||||
headers = headers,
|
headers = headers,
|
||||||
@@ -74,7 +74,13 @@ function httpclient:request(log, method, url, query_args, body, headers)
|
|||||||
}
|
}
|
||||||
local response = table.concat(result)
|
local response = table.concat(result)
|
||||||
|
|
||||||
log("<~< %d", c)
|
if not (r and statusline) then
|
||||||
|
local message = #response > 0 and response or "unknown error"
|
||||||
|
log("<!< error: %s", message)
|
||||||
|
return 0, {}, message
|
||||||
|
end
|
||||||
|
|
||||||
|
log("<~< %d (%s)", c, statusline)
|
||||||
log("<<< %s", response)
|
log("<<< %s", response)
|
||||||
|
|
||||||
return c, h, response
|
return c, h, response
|
||||||
|
|||||||
Reference in New Issue
Block a user