Comparison

net/http.lua @ 10563:e8db377a2983

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Tue, 24 Dec 2019 00:39:45 +0100
parent 10464:8d3acf16c404
child 10803:71d04bd6cadd
comparison
equal deleted inserted replaced
10562:670afc079f68 10563:e8db377a2983
38 38
39 -- Request-related helper functions 39 -- Request-related helper functions
40 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); return err; end 40 local function handleerr(err) log("error", "Traceback[http]: %s", traceback(tostring(err), 2)); return err; end
41 local function log_if_failed(req, ret, ...) 41 local function log_if_failed(req, ret, ...)
42 if not ret then 42 if not ret then
43 log("error", "Request '%s': error in callback: %s", req.id, tostring((...))); 43 log("error", "Request '%s': error in callback: %s", req.id, (...));
44 if not req.suppress_errors then 44 if not req.suppress_errors then
45 error(...); 45 error(...);
46 end 46 end
47 end 47 end
48 return ...; 48 return ...;
148 148
149 function listener.onincoming(conn, data) 149 function listener.onincoming(conn, data)
150 local request = requests[conn]; 150 local request = requests[conn];
151 151
152 if not request then 152 if not request then
153 log("warn", "Received response from connection %s with no request attached!", tostring(conn)); 153 log("warn", "Received response from connection %s with no request attached!", conn);
154 return; 154 return;
155 end 155 end
156 156
157 if data and request.reader then 157 if data and request.reader then
158 request:reader(data); 158 request:reader(data);
258 local sslctx = false; 258 local sslctx = false;
259 if using_https then 259 if using_https then
260 sslctx = ex and ex.sslctx or self.options and self.options.sslctx; 260 sslctx = ex and ex.sslctx or self.options and self.options.sslctx;
261 end 261 end
262 262
263 local http_service = basic_resolver.new(host, port_number); 263 local http_service = basic_resolver.new(host, port_number, "tcp", { servername = req.host });
264 connect(http_service, listener, { sslctx = sslctx }, req); 264 connect(http_service, listener, { sslctx = sslctx }, req);
265 265
266 self.events.fire_event("request", { http = self, request = req, url = u }); 266 self.events.fire_event("request", { http = self, request = req, url = u });
267 return req; 267 return req;
268 end 268 end
283 }; 283 };
284 return http; 284 return http;
285 end 285 end
286 286
287 local default_http = new({ 287 local default_http = new({
288 sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" } }; 288 sslctx = { mode = "client", protocol = "sslv23", options = { "no_sslv2", "no_sslv3" }, alpn = "http/1.1" };
289 suppress_errors = true; 289 suppress_errors = true;
290 }); 290 });
291 291
292 return { 292 return {
293 request = function (u, ex, callback) 293 request = function (u, ex, callback)