Diff

net/http.lua @ 5488:0880a079d830

net.http: When HTTP request fails due to a network or SSL error, call the callback to let it know
author Matthew Wild <mwild1@gmail.com>
date Thu, 18 Apr 2013 00:08:58 +0100
parent 5466:e3b9dc9dd940
child 5505:0b6a99e6c1b1
line wrap: on
line diff
--- a/net/http.lua	Wed Apr 17 15:28:20 2013 -0400
+++ b/net/http.lua	Thu Apr 18 00:08:58 2013 +0100
@@ -66,24 +66,29 @@
 function listener.ondisconnect(conn, err)
 	local request = requests[conn];
 	if request and request.conn then
-		request:reader(nil);
+		request:reader(nil, err);
 	end
 	requests[conn] = nil;
 end
 
-local function request_reader(request, data)
+local function request_reader(request, data, err)
 	if not request.parser then
-		if not data then return; end
-		local function success_cb(r)
+		local function error_cb(reason)
 			if request.callback then
-				request.callback(r.body, r.code, r, request);
+				request.callback(reason or "connection-closed", 0, request);
 				request.callback = nil;
 			end
 			destroy_request(request);
 		end
-		local function error_cb(r)
+		
+		if not data then
+			error_cb(err);
+			return;
+		end
+		
+		local function success_cb(r)
 			if request.callback then
-				request.callback(r or "connection-closed", 0, request);
+				request.callback(r.body, r.code, r, request);
 				request.callback = nil;
 			end
 			destroy_request(request);