Diff

net/http.lua @ 11017:1f41f38a92f7

Merge 0.11->trunk
author Matthew Wild <mwild1@gmail.com>
date Sat, 08 Aug 2020 13:14:11 +0100
parent 10995:e18a913aed2d
parent 11016:5176d9f727f6
child 11048:160308b4b384
line wrap: on
line diff
--- a/net/http.lua	Sat Jul 25 17:26:11 2020 +0200
+++ b/net/http.lua	Sat Aug 08 13:14:11 2020 +0100
@@ -58,6 +58,16 @@
 	end
 end
 
+local function cancel_request(request, reason)
+	if request.callback then
+		request.callback(reason or "cancelled", 0, request);
+		request.callback = nil;
+	end
+	if request.conn then
+		destroy_request(request);
+	end
+end
+
 local function request_reader(request, data, err)
 	if not request.parser then
 		local function error_cb(reason)
@@ -107,6 +117,7 @@
 	end
 	req.reader = request_reader;
 	req.state = "status";
+	req.cancel = cancel_request;
 
 	requests[req.conn] = req;
 
@@ -318,4 +329,5 @@
 	urldecode = util_http.urldecode;
 	formencode = util_http.formencode;
 	formdecode = util_http.formdecode;
+	destroy_request = destroy_request;
 };