Comparison

net/http.lua @ 6791:e813e8cf6046

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Thu, 20 Aug 2015 13:05:22 +0200
parent 6502:8fed6ea12098
parent 6780:647adfd8f738
child 6826:17a4e89a4780
comparison
equal deleted inserted replaced
6776:4412a2307c89 6791:e813e8cf6046
21 tonumber, tostring, xpcall, select, debug.traceback; 21 tonumber, tostring, xpcall, select, debug.traceback;
22 local assert, error = assert, error 22 local assert, error = assert, error
23 23
24 local log = require "util.logger".init("http"); 24 local log = require "util.logger".init("http");
25 25
26 module "http" 26 local _ENV = nil;
27 27
28 local requests = {}; -- Open requests 28 local requests = {}; -- Open requests
29 29
30 local listener = { default_port = 80, default_mode = "*a" }; 30 local listener = { default_port = 80, default_mode = "*a" };
31 31
71 requests[conn] = nil; 71 requests[conn] = nil;
72 end 72 end
73 73
74 function listener.ondetach(conn) 74 function listener.ondetach(conn)
75 requests[conn] = nil; 75 requests[conn] = nil;
76 end
77
78 local function destroy_request(request)
79 if request.conn then
80 request.conn = nil;
81 request.handler:close()
82 end
76 end 83 end
77 84
78 local function request_reader(request, data, err) 85 local function request_reader(request, data, err)
79 if not request.parser then 86 if not request.parser then
80 local function error_cb(reason) 87 local function error_cb(reason)
104 end 111 end
105 request.parser:feed(data); 112 request.parser:feed(data);
106 end 113 end
107 114
108 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end 115 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end
109 function request(u, ex, callback) 116 local function request(u, ex, callback)
110 local req = url.parse(u); 117 local req = url.parse(u);
111 118
112 if not (req and req.host) then 119 if not (req and req.host) then
113 callback(nil, 0, req); 120 callback(nil, 0, req);
114 return nil, "invalid-url"; 121 return nil, "invalid-url";
182 189
183 requests[req.handler] = req; 190 requests[req.handler] = req;
184 return req; 191 return req;
185 end 192 end
186 193
187 function destroy_request(request) 194 return {
188 if request.conn then 195 request = request;
189 request.conn = nil; 196
190 request.handler:close() 197 -- COMPAT
191 end 198 urlencode = util_http.urlencode;
192 end 199 urldecode = util_http.urldecode;
193 200 formencode = util_http.formencode;
194 local urlencode, urldecode = util_http.urlencode, util_http.urldecode; 201 formdecode = util_http.formdecode;
195 local formencode, formdecode = util_http.formencode, util_http.formdecode; 202 };
196
197 _M.urlencode, _M.urldecode = urlencode, urldecode;
198 _M.formencode, _M.formdecode = formencode, formdecode;
199
200 return _M;