# HG changeset patch
# User Waqas Hussain <waqas20@gmail.com>
# Date 1288904996 -18000
# Node ID 98f9dca3eb94a2ae2670bc79a87798717aacf908
# Parent  579c087059fcbe1ac9904c6cf84e1e308e9a6166
util.httpstream: Move HTTP header parsing into its own function.

diff -r 579c087059fc -r 98f9dca3eb94 util/httpstream.lua
--- a/util/httpstream.lua	Thu Nov 04 20:12:42 2010 +0500
+++ b/util/httpstream.lua	Fri Nov 05 02:09:56 2010 +0500
@@ -26,14 +26,7 @@
 		data = data:sub(n + 1);
 		return r;
 	end
-	
-	while true do
-		-- read status line
-		local status_line = readline();
-		local method, path, httpversion = status_line:match("^(%S+)%s+(%S+)%s+HTTP/(%S+)$");
-		if not method then coroutine.yield("invalid-status-line"); end
-		-- TODO parse url
-		
+	local function readheaders()
 		local headers = {}; -- read headers
 		while true do
 			local line = readline();
@@ -43,6 +36,15 @@
 			key = key:lower();
 			headers[key] = headers[key] and headers[key]..","..val or val;
 		end
+	end
+	
+	while true do
+		-- read status line
+		local status_line = readline();
+		local method, path, httpversion = status_line:match("^(%S+)%s+(%S+)%s+HTTP/(%S+)$");
+		if not method then coroutine.yield("invalid-status-line"); end
+		-- TODO parse url
+		local headers = readheaders();
 		
 		-- read body
 		local len = tonumber(headers["content-length"]);