From 0aa232965c511c9317b1217018190159d44b88d1 Mon Sep 17 00:00:00 2001 From: Adrian Perez de Castro Date: Mon, 4 Jul 2016 17:52:39 +0300 Subject: [PATCH] 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. --- matrix/httpclient/luasocket.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/matrix/httpclient/luasocket.lua b/matrix/httpclient/luasocket.lua index ef0876e..f54293f 100644 --- a/matrix/httpclient/luasocket.lua +++ b/matrix/httpclient/luasocket.lua @@ -65,7 +65,7 @@ function httpclient:request(log, method, url, query_args, body, headers) source = stringsource(body) end local result = {} - local r, c, h = make_request { + local r, c, h, statusline = make_request { url = url, method = method, headers = headers, @@ -74,7 +74,13 @@ function httpclient:request(log, method, url, query_args, body, headers) } local response = table.concat(result) - log("<~< %d", c) + if not (r and statusline) then + local message = #response > 0 and response or "unknown error" + log("