Comparison

net/http/server.lua @ 4788:e14f5a156571

net.http.server: Code cleanup/adjustment now that send_response() accepts response.body
author Matthew Wild <mwild1@gmail.com>
date Sat, 28 Apr 2012 19:36:57 +0100
parent 4787:1d753fecf95b
child 5300:fcb1be0b4a5c
comparison
equal deleted inserted replaced
4787:1d753fecf95b 4788:e14f5a156571
194 local payload = { request = request, response = response }; 194 local payload = { request = request, response = response };
195 --log("debug", "Firing event: %s", event); 195 --log("debug", "Firing event: %s", event);
196 local result = events.fire_event(event, payload); 196 local result = events.fire_event(event, payload);
197 if result ~= nil then 197 if result ~= nil then
198 if result ~= true then 198 if result ~= true then
199 local body = ""; 199 local body;
200 local result_type = type(result); 200 local result_type = type(result);
201 if result_type == "number" then 201 if result_type == "number" then
202 response.status_code = result; 202 response.status_code = result;
203 if result >= 400 then 203 if result >= 400 then
204 body = events.fire_event("http-error", { code = result }); 204 body = events.fire_event("http-error", { code = result });
205 end 205 end
206 elseif result_type == "string" then 206 elseif result_type == "string" then
207 body = result; 207 body = result;
208 elseif result_type == "table" then 208 elseif result_type == "table" then
209 body = result.body;
210 result.body = nil;
211 for k, v in pairs(result) do 209 for k, v in pairs(result) do
212 response[k] = v; 210 response[k] = v;
213 end 211 end
214 end 212 end
215 response:send(body); 213 response:send(body);