Changeset

2670:35f36a53c671

Merge with 0.7
author Matthew Wild <mwild1@gmail.com>
date Fri, 19 Feb 2010 02:59:00 +0000
parents 2668:4ddacf58f43d (current diff) 2669:9dbe9acf82e8 (diff)
children 2677:467568f1117d
files
diffstat 1 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/net/http.lua	Thu Feb 18 19:00:50 2010 +0000
+++ b/net/http.lua	Fri Feb 19 02:59:00 2010 +0000
@@ -73,22 +73,31 @@
 	elseif request.state == "headers" then
 		print("Reading headers...")
 		local pos = startpos;
-		local headers = request.responseheaders or {};
+		local headers, headers_complete = request.responseheaders;
+		if not headers then
+			headers = {};
+			request.responseheaders = headers;
+		end
 		for line in data:sub(startpos, -1):gmatch("(.-)\r\n") do
 			startpos = startpos + #line + 2;
 			local k, v = line:match("(%S+): (.+)");
 			if k and v then
 				headers[k:lower()] = v;
-				print("Header: "..k:lower().." = "..v);
+				--print("Header: "..k:lower().." = "..v);
 			elseif #line == 0 then
-				request.responseheaders = headers;
+				headers_complete = true;
 				break;
 			else
 				print("Unhandled header line: "..line);
 			end
 		end
+		if not headers_complete then return; end
 		-- Reached the end of the headers
-		request.state = "body";
+		if not expectbody(request, request.code) then
+			request.callback(nil, request.code, request);
+			return;
+		end
+			request.state = "body";
 		if #data > startpos then
 			return request_reader(request, data, startpos);
 		end
@@ -102,7 +111,7 @@
 		
 		request.code, request.responseversion = code, http;
 		
-		if request.onlystatus or not expectbody(request, code) then
+		if request.onlystatus then
 			if request.callback then
 				request.callback(nil, code, request);
 			end