Software /
code /
prosody
Comparison
net/http.lua @ 8690:0f6623712239
net.http: Allow enabling/disabling error suppression, useful for tests
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 24 Mar 2018 11:29:33 +0000 |
parent | 8689:c7122fbe1600 |
child | 8707:fd39c44c0113 |
comparison
equal
deleted
inserted
replaced
8689:c7122fbe1600 | 8690:0f6623712239 |
---|---|
35 | 35 |
36 local listener = { default_port = 80, default_mode = "*a" }; | 36 local listener = { default_port = 80, default_mode = "*a" }; |
37 | 37 |
38 -- Request-related helper functions | 38 -- Request-related helper functions |
39 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); return err; end | 39 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); return err; end |
40 local function log_if_failed(id, ret, ...) | 40 local function log_if_failed(req, ret, ...) |
41 if not ret then | 41 if not ret then |
42 log("error", "Request '%s': error in callback: %s", id, tostring((...))); | 42 log("error", "Request '%s': error in callback: %s", req.id, tostring((...))); |
43 if not req.suppress_errors then | |
44 error(...); | |
45 end | |
43 end | 46 end |
44 return ...; | 47 return ...; |
45 end | 48 end |
46 | 49 |
47 local function destroy_request(request) | 50 local function destroy_request(request) |
235 for k, v in pairs(ex.headers) do | 238 for k, v in pairs(ex.headers) do |
236 headers[k] = v; | 239 headers[k] = v; |
237 end | 240 end |
238 end | 241 end |
239 req.insecure = ex.insecure; | 242 req.insecure = ex.insecure; |
243 req.suppress_errors = ex.suppress_errors; | |
240 end | 244 end |
241 | 245 |
242 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); | 246 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); |
243 | 247 |
244 -- Attach to request object | 248 -- Attach to request object |
274 return http; | 278 return http; |
275 end | 279 end |
276 | 280 |
277 local default_http = new({ | 281 local default_http = new({ |
278 sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; | 282 sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; |
283 suppress_errors = true; | |
279 }); | 284 }); |
280 | 285 |
281 return { | 286 return { |
282 request = function (u, ex, callback) | 287 request = function (u, ex, callback) |
283 return default_http:request(u, ex, callback); | 288 return default_http:request(u, ex, callback); |