Software /
code /
prosody
Comparison
net/http/server.lua @ 4659:d53142e90cd0
net.http.server: Fix legacy net.httpserver fallback (httpserver is no longer a global).
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sun, 22 Apr 2012 23:44:21 +0500 |
parent | 4634:8e582afc214d |
child | 4668:cce0c739b0d7 |
comparison
equal
deleted
inserted
replaced
4658:de04897cb8fe | 4659:d53142e90cd0 |
---|---|
11 local xpcall = xpcall; | 11 local xpcall = xpcall; |
12 local debug = debug; | 12 local debug = debug; |
13 local tostring = tostring; | 13 local tostring = tostring; |
14 local codes = require "net.http.codes"; | 14 local codes = require "net.http.codes"; |
15 local _G = _G; | 15 local _G = _G; |
16 local legacy_httpserver = require "net.httpserver"; | |
16 | 17 |
17 local _M = {}; | 18 local _M = {}; |
18 | 19 |
19 local sessions = {}; | 20 local sessions = {}; |
20 local handlers = {}; | 21 local handlers = {}; |
157 end | 158 end |
158 end | 159 end |
159 function _M.legacy_handler(request, response) | 160 function _M.legacy_handler(request, response) |
160 log("debug", "Invoking legacy handler"); | 161 log("debug", "Invoking legacy handler"); |
161 local base = request.path:match("^/([^/?]+)"); | 162 local base = request.path:match("^/([^/?]+)"); |
162 local legacy_server = _G.httpserver and _G.httpserver.new.http_servers[5280]; | 163 local legacy_server = legacy_httpserver and legacy_httpserver.new.http_servers[5280]; |
163 local handler = legacy_server and legacy_server.handlers[base]; | 164 local handler = legacy_server and legacy_server.handlers[base]; |
164 if not handler then handler = _G.httpserver and _G.httpserver.set_default_handler.default_handler; end | 165 if not handler then handler = legacy_httpserver and legacy_httpserver.set_default_handler.default_handler; end |
165 if handler then | 166 if handler then |
166 -- add legacy properties to request object | 167 -- add legacy properties to request object |
167 request.url = { path = request.path }; | 168 request.url = { path = request.path }; |
168 request.handler = response.conn; | 169 request.handler = response.conn; |
169 request.id = tostring{}:match("%x+$"); | 170 request.id = tostring{}:match("%x+$"); |