diff options
-rw-r--r-- | default.lua | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/default.lua b/default.lua index 56e5082..bc409ef 100644 --- a/default.lua +++ b/default.lua @@ -13,9 +13,8 @@ local RESPONSE = [[<!doctype html> ]] local HEADER = "%s<tr><td>%s<td>%s\n" ---- Default client request handler. --- TODO: Add documentation once request and response API are more stable. -return function (stream) +local +function handle_request (stream) local status = 200 local method, path, version, h = stream:read(" ", " ", "\r\n", "\r\n\r\n") local headers = {} @@ -24,6 +23,7 @@ return function (stream) headers[header:lower()] = value end end + local connection = headers.connection or "close" if method == nil or path == nil or version ~= "HTTP/1.1" or h == nil then status = 400 end @@ -34,8 +34,18 @@ return function (stream) local response = RESPONSE:format(method, path, version, headers_table) stream:write( "HTTP/1.1 ", status, "\r\n", - "Connection: close\r\n", + "Connection: ", connection, "\r\n", "Content-Length: ", #response, "\r\n", "Content-Type: text/html\r\n\r\n", response) stream:flush() + return connection +end + +--- Default client request handler. +-- TODO: Add documentation once request and response API are more stable. +return +function (stream) + repeat + local connection = handle_request(stream) + until connection == "close" end |