28 |
28 |
29 local function send_response(request, response) |
29 local function send_response(request, response) |
30 -- Write status line |
30 -- Write status line |
31 local resp; |
31 local resp; |
32 if response.body then |
32 if response.body then |
33 log("debug", "Sending response to %s: %s", request.id, response.body); |
33 log("debug", "Sending response to %s", request.id); |
34 resp = { "HTTP/1.0 ", response.status or "200 OK", "\r\n"}; |
34 resp = { "HTTP/1.0 ", response.status or "200 OK", "\r\n"}; |
35 local h = response.headers; |
35 local h = response.headers; |
36 if h then |
36 if h then |
37 for k, v in pairs(h) do |
37 for k, v in pairs(h) do |
38 t_insert(resp, k); |
38 t_insert(resp, k); |
97 local response = callback(request.method, request.body and t_concat(request.body), request); |
97 local response = callback(request.method, request.body and t_concat(request.body), request); |
98 if response then |
98 if response then |
99 if response == true and not request.destroyed then |
99 if response == true and not request.destroyed then |
100 -- Keep connection open, we will reply later |
100 -- Keep connection open, we will reply later |
101 log("warn", "Request %s left open, on_destroy is %s", request.id, tostring(request.on_destroy)); |
101 log("warn", "Request %s left open, on_destroy is %s", request.id, tostring(request.on_destroy)); |
102 else |
102 elseif response ~= true then |
103 -- Assume response |
103 -- Assume response |
104 send_response(request, response); |
104 send_response(request, response); |
105 destroy_request(request); |
105 destroy_request(request); |
106 end |
106 end |
107 else |
107 else |