Software /
code /
prosody
Comparison
net/http.lua @ 7523:3c40b972260e
Merge 0.10 -> trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 27 Jul 2016 14:08:32 +0100 |
parent | 7465:f1923f00b7de |
parent | 7520:fc6c24cb3599 |
child | 7798:74cfec1fe5a2 |
comparison
equal
deleted
inserted
replaced
7518:829ebe806e82 | 7523:3c40b972260e |
---|---|
115 end | 115 end |
116 | 116 |
117 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end | 117 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); end |
118 local function log_if_failed(id, ret, ...) | 118 local function log_if_failed(id, ret, ...) |
119 if not ret then | 119 if not ret then |
120 log("error", "Request %s: error in callback: %s", id, tostring((...))); | 120 log("error", "Request '%s': error in callback: %s", id, tostring((...))); |
121 end | 121 end |
122 return ...; | 122 return ...; |
123 end | 123 end |
124 | 124 |
125 local function request(u, ex, callback) | 125 local function request(u, ex, callback) |
170 headers[k] = v; | 170 headers[k] = v; |
171 end | 171 end |
172 end | 172 end |
173 end | 173 end |
174 | 174 |
175 log("debug", "Making %s %s request %s to %s", req.scheme, method or "GET", req.id, (ex and ex.suppress_url and host_header) or u); | 175 log("debug", "Making %s %s request '%s' to %s", req.scheme:upper(), method or "GET", req.id, (ex and ex.suppress_url and host_header) or u); |
176 | 176 |
177 -- Attach to request object | 177 -- Attach to request object |
178 req.method, req.headers, req.body = method, headers, body; | 178 req.method, req.headers, req.body = method, headers, body; |
179 | 179 |
180 local using_https = req.scheme == "https"; | 180 local using_https = req.scheme == "https"; |
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 |
199 req.callback = function (content, code, request, response) | 199 req.callback = function (content, code, request, response) |
200 log("debug", "request %s: Calling callback, status %s", req.id, code or "---"); | 200 log("debug", "Request '%s': Calling callback, status %s", req.id, code or "---"); |
201 return log_if_failed(req.id, xpcall(function () return callback(content, code, request, response) end, handleerr)); | 201 return log_if_failed(req.id, xpcall(function () return callback(content, code, request, response) end, handleerr)); |
202 end | 202 end |
203 req.reader = request_reader; | 203 req.reader = request_reader; |
204 req.state = "status"; | 204 req.state = "status"; |
205 | 205 |