aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2010-11-05 02:09:56 +0500
committerWaqas Hussain <waqas20@gmail.com>2010-11-05 02:09:56 +0500
commit64cf101b58958d0bdabe7ab00114e3f9bba7a0f4 (patch)
tree2be180e0b7b8e39a427b1cf5eadeebe8412f6805 /util
parent309c2b4e42a49f9ff25b6f842474c0469036e0e7 (diff)
downloadprosody-64cf101b58958d0bdabe7ab00114e3f9bba7a0f4.tar.gz
prosody-64cf101b58958d0bdabe7ab00114e3f9bba7a0f4.zip
util.httpstream: Move HTTP header parsing into its own function.
Diffstat (limited to 'util')
-rw-r--r--util/httpstream.lua18
1 files changed, 10 insertions, 8 deletions
diff --git a/util/httpstream.lua b/util/httpstream.lua
index 95d51726..e2127b80 100644
--- a/util/httpstream.lua
+++ b/util/httpstream.lua
@@ -26,14 +26,7 @@ local function parser(data, success_cb)
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 @@ local function parser(data, success_cb)
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"]);