Software /
code /
prosody
Comparison
net/http.lua @ 8534:c071cabfa066
net.http: Remove use of 'conn' (raw socket object returned by addclient)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 23 Feb 2018 16:20:45 +0000 |
parent | 8201:a0ad62a269df |
child | 8535:b6f3b34ecc03 |
comparison
equal
deleted
inserted
replaced
8533:66cdf5c7af85 | 8534:c071cabfa066 |
---|---|
98 function listener.ondetach(conn) | 98 function listener.ondetach(conn) |
99 requests[conn] = nil; | 99 requests[conn] = nil; |
100 end | 100 end |
101 | 101 |
102 local function destroy_request(request) | 102 local function destroy_request(request) |
103 if request.conn then | 103 local conn = request.conn; |
104 if conn then | |
104 request.conn = nil; | 105 request.conn = nil; |
105 request.handler:close() | 106 conn:close() |
106 end | 107 end |
107 end | 108 end |
108 | 109 |
109 local function request_reader(request, data, err) | 110 local function request_reader(request, data, err) |
110 if not request.parser then | 111 if not request.parser then |
219 local sslctx = false; | 220 local sslctx = false; |
220 if using_https then | 221 if using_https then |
221 sslctx = ex and ex.sslctx or self.options and self.options.sslctx; | 222 sslctx = ex and ex.sslctx or self.options and self.options.sslctx; |
222 end | 223 end |
223 | 224 |
224 local handler, conn = server.addclient(host, port_number, listener, "*a", sslctx) | 225 local handler, ret = server.addclient(host, port_number, listener, "*a", sslctx) |
225 if not handler then | 226 if not handler then |
226 self.events.fire_event("request-connection-error", { http = self, request = req, url = u, err = conn }); | 227 self.events.fire_event("request-connection-error", { http = self, request = req, url = u, err = ret }); |
227 callback(conn, 0, req); | 228 callback(ret, 0, req); |
228 return nil, conn; | 229 return nil, ret; |
229 end | 230 end |
230 req.handler, req.conn = handler, conn | 231 req.conn = handler |
231 req.write = function (...) return req.handler:write(...); end | 232 req.write = function (...) return req.conn:write(...); end |
232 | 233 |
233 req.callback = function (content, code, response, request) | 234 req.callback = function (content, code, response, request) |
234 do | 235 do |
235 local event = { http = self, url = u, request = req, response = response, content = content, code = code, callback = callback }; | 236 local event = { http = self, url = u, request = req, response = response, content = content, code = code, callback = callback }; |
236 self.events.fire_event("response", event); | 237 self.events.fire_event("response", event); |
241 return log_if_failed(req.id, xpcall(function () return callback(content, code, request, response) end, handleerr)); | 242 return log_if_failed(req.id, xpcall(function () return callback(content, code, request, response) end, handleerr)); |
242 end | 243 end |
243 req.reader = request_reader; | 244 req.reader = request_reader; |
244 req.state = "status"; | 245 req.state = "status"; |
245 | 246 |
246 requests[req.handler] = req; | 247 requests[req.conn] = req; |
247 | 248 |
248 self.events.fire_event("request", { http = self, request = req, url = u }); | 249 self.events.fire_event("request", { http = self, request = req, url = u }); |
249 return req; | 250 return req; |
250 end | 251 end |
251 | 252 |