Comparison

net/http/server.lua @ 5333:760c345dc7a1

net.http.server: Ensure HTTP callbacks are never called recursively for pipelined requests.
author Waqas Hussain <waqas20@gmail.com>
date Tue, 26 Feb 2013 19:41:52 +0500
parent 5300:fcb1be0b4a5c
child 5404:ae9a47e579d7
comparison
equal deleted inserted replaced
5332:5b73ac268a9e 5333:760c345dc7a1
87 function listener.onconnect(conn) 87 function listener.onconnect(conn)
88 local secure = conn:ssl() and true or nil; 88 local secure = conn:ssl() and true or nil;
89 local pending = {}; 89 local pending = {};
90 local waiting = false; 90 local waiting = false;
91 local function process_next() 91 local function process_next()
92 --if waiting then log("debug", "can't process_next, waiting"); return; end 92 if waiting then log("debug", "can't process_next, waiting"); return; end
93 if sessions[conn] and #pending > 0 then 93 waiting = true;
94 while sessions[conn] and #pending > 0 do
94 local request = t_remove(pending); 95 local request = t_remove(pending);
95 --log("debug", "process_next: %s", request.path); 96 --log("debug", "process_next: %s", request.path);
96 waiting = true;
97 --handle_request(conn, request, process_next); 97 --handle_request(conn, request, process_next);
98 _1, _2, _3 = conn, request, process_next; 98 _1, _2, _3 = conn, request, process_next;
99 if not xpcall(_handle_request, _traceback_handler) then 99 if not xpcall(_handle_request, _traceback_handler) then
100 conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = last_err })); 100 conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = last_err }));
101 conn:close(); 101 conn:close();
102 end 102 end
103 else 103 end
104 --log("debug", "ready for more"); 104 --log("debug", "ready for more");
105 waiting = false; 105 waiting = false;
106 end
107 end 106 end
108 local function success_cb(request) 107 local function success_cb(request)
109 --log("debug", "success_cb: %s", request.path); 108 --log("debug", "success_cb: %s", request.path);
109 if waiting then
110 log("error", "http connection handler is not reentrant: %s", request.path);
111 assert(false, "http connection handler is not reentrant");
112 end
110 request.secure = secure; 113 request.secure = secure;
111 t_insert(pending, request); 114 t_insert(pending, request);
112 if not waiting then 115 process_next();
113 process_next();
114 end
115 end 116 end
116 local function error_cb(err) 117 local function error_cb(err)
117 log("debug", "error_cb: %s", err or "<nil>"); 118 log("debug", "error_cb: %s", err or "<nil>");
118 -- FIXME don't close immediately, wait until we process current stuff 119 -- FIXME don't close immediately, wait until we process current stuff
119 -- FIXME if err, send off a bad-request response 120 -- FIXME if err, send off a bad-request response