diff options
author | Kim Alvefur <zash@zash.se> | 2021-02-12 14:47:27 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-02-12 14:47:27 +0100 |
commit | 3c96f613c0b14c3114e900fec3f9d6eae11e5e77 (patch) | |
tree | 14c16b6c853599e8278af7c489433b099a76d91c /net | |
parent | f0202d38c226c5e1657dc48319ae5f1dd81c1c2b (diff) | |
download | prosody-3c96f613c0b14c3114e900fec3f9d6eae11e5e77.tar.gz prosody-3c96f613c0b14c3114e900fec3f9d6eae11e5e77.zip |
net.http.server: Allow storing more than the parser in the session
Storing the async thread on the connection was weird.
Diffstat (limited to 'net')
-rw-r--r-- | net/http/server.lua | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/net/http/server.lua b/net/http/server.lua index c35ee670..7c79edee 100644 --- a/net/http/server.lua +++ b/net/http/server.lua @@ -96,41 +96,42 @@ end, -1); local runner_callbacks = {}; function runner_callbacks:ready() - self.data:resume(); + self.data.conn:resume(); end function runner_callbacks:waiting() - self.data:pause(); + self.data.conn:pause(); end function runner_callbacks:error(err) log("error", "Traceback[httpserver]: %s", err); - self.data:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = err })); - self.data:close(); + self.data.conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = err })); + self.data.conn:close(); end function listener.onconnect(conn) + local session = { conn = conn }; local secure = conn:ssl() and true or nil; - conn._thread = async.runner(function (request) + session.thread = async.runner(function (request) local wait, done = async.waiter(); handle_request(conn, request, done); wait(); - end, runner_callbacks, conn); + end, runner_callbacks, session); local function success_cb(request) --log("debug", "success_cb: %s", request.path); request.secure = secure; - conn._thread:run(request); + session.thread:run(request); end local function error_cb(err) log("debug", "error_cb: %s", err or "<nil>"); -- FIXME don't close immediately, wait until we process current stuff -- FIXME if err, send off a bad-request response - sessions[conn] = nil; conn:close(); end local function options_cb() return options; end - sessions[conn] = parser_new(success_cb, error_cb, "server", options_cb); + session.parser = parser_new(success_cb, error_cb, "server", options_cb); + sessions[conn] = session; end function listener.ondisconnect(conn) @@ -149,7 +150,7 @@ function listener.ondetach(conn) end function listener.onincoming(conn, data) - sessions[conn]:feed(data); + sessions[conn].parser:feed(data); end function listener.ondrain(conn) |