Software /
code /
prosody
Comparison
net/httpserver.lua @ 1666:d1243b321c45
net.httpserver: Allow overriding default request handler
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 11 Aug 2009 20:49:19 +0100 |
parent | 1661:33b1aee4b77f |
child | 1868:36e1238db2f2 |
comparison
equal
deleted
inserted
replaced
1665:2c72b725384e | 1666:d1243b321c45 |
---|---|
87 if not base then | 87 if not base then |
88 base = path:match("^http://[^/?]+/([^/?]+)"); | 88 base = path:match("^http://[^/?]+/([^/?]+)"); |
89 end | 89 end |
90 | 90 |
91 callback = (request.server and request.server.handlers[base]) or default_handler; | 91 callback = (request.server and request.server.handlers[base]) or default_handler; |
92 if callback == default_handler then | |
93 log("debug", "Default callback for this request (base: "..tostring(base)..")") | |
94 end | |
95 end | 92 end |
96 if callback then | 93 if callback then |
97 if err then | 94 if err then |
98 log("debug", "Request error: "..err); | 95 log("debug", "Request error: "..err); |
99 if not callback(nil, err, request) then | 96 if not callback(nil, err, request) then |
249 if params.base then | 246 if params.base then |
250 http_server.handlers[params.base] = params.handler; | 247 http_server.handlers[params.base] = params.handler; |
251 end | 248 end |
252 end | 249 end |
253 | 250 |
251 function set_default_handler(handler) | |
252 default_handler = handler; | |
253 end | |
254 | |
254 function new_from_config(ports, default_base, handle_request) | 255 function new_from_config(ports, default_base, handle_request) |
255 for _, options in ipairs(ports) do | 256 for _, options in ipairs(ports) do |
256 local port, base, ssl, interface = 5280, default_base, false, nil; | 257 local port, base, ssl, interface = 5280, default_base, false, nil; |
257 if type(options) == "number" then | 258 if type(options) == "number" then |
258 port = options; | 259 port = options; |