Software / code / prosody
Comparison
net/http.lua @ 8045:55a56dc935f2
net.http: Pass error all the way to callback
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 02 Apr 2017 00:24:07 +0200 |
| parent | 7793:4f1b5596250b |
| child | 8046:1bf47706aefb |
| child | 8113:cfb5ab763384 |
comparison
equal
deleted
inserted
replaced
| 8042:5d5afaafac0f | 8045:55a56dc935f2 |
|---|---|
| 66 end | 66 end |
| 67 | 67 |
| 68 function listener.ondisconnect(conn, err) | 68 function listener.ondisconnect(conn, err) |
| 69 local request = requests[conn]; | 69 local request = requests[conn]; |
| 70 if request and request.conn then | 70 if request and request.conn then |
| 71 request:reader(nil, err); | 71 request:reader(nil, err or "closed"); |
| 72 end | 72 end |
| 73 requests[conn] = nil; | 73 requests[conn] = nil; |
| 74 end | 74 end |
| 75 | 75 |
| 76 function listener.ondetach(conn) | 76 function listener.ondetach(conn) |
| 124 | 124 |
| 125 local function request(u, ex, callback) | 125 local function request(u, ex, callback) |
| 126 local req = url.parse(u); | 126 local req = url.parse(u); |
| 127 | 127 |
| 128 if not (req and req.host) then | 128 if not (req and req.host) then |
| 129 callback(nil, 0, req); | 129 callback("invalid-url", 0, req); |
| 130 return nil, "invalid-url"; | 130 return nil, "invalid-url"; |
| 131 end | 131 end |
| 132 | 132 |
| 133 if not req.path then | 133 if not req.path then |
| 134 req.path = "/"; | 134 req.path = "/"; |
| 188 sslctx = ex and ex.sslctx or { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; | 188 sslctx = ex and ex.sslctx or { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; |
| 189 end | 189 end |
| 190 | 190 |
| 191 local handler, conn = server.addclient(host, port_number, listener, "*a", sslctx) | 191 local handler, conn = server.addclient(host, port_number, listener, "*a", sslctx) |
| 192 if not handler then | 192 if not handler then |
| 193 callback(nil, 0, req); | 193 callback(conn, 0, req); |
| 194 return nil, conn; | 194 return nil, conn; |
| 195 end | 195 end |
| 196 req.handler, req.conn = handler, conn | 196 req.handler, req.conn = handler, conn |
| 197 req.write = function (...) return req.handler:write(...); end | 197 req.write = function (...) return req.handler:write(...); end |
| 198 | 198 |