use table for multi header key

This commit is contained in:
Cloud Wu
2015-03-16 20:01:22 +08:00
parent c287f050c1
commit 92b7b7beff
2 changed files with 17 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ local internal = require "http.internal"
local table = table local table = table
local string = string local string = string
local type = type
local httpd = {} local httpd = {}
@@ -113,7 +114,13 @@ local function writeall(writefunc, statuscode, bodyfunc, header)
writefunc(statusline) writefunc(statusline)
if header then if header then
for k,v in pairs(header) do for k,v in pairs(header) do
writefunc(string.format("%s: %s\r\n", k,v)) if type(v) == "table" then
for _,v in ipairs(v) do
writefunc(string.format("%s: %s\r\n", k,v))
end
else
writefunc(string.format("%s: %s\r\n", k,v))
end
end end
end end
local t = type(bodyfunc) local t = type(bodyfunc)

View File

@@ -1,3 +1,6 @@
local table = table
local type = type
local M = {} local M = {}
local LIMIT = 8192 local LIMIT = 8192
@@ -83,7 +86,12 @@ function M.parseheader(lines, from, header)
end end
name = name:lower() name = name:lower()
if header[name] then if header[name] then
header[name] = header[name] .. ", " .. value local v = header[name]
if type(v) == "table" then
table.insert(v, value)
else
header[name] = { v , value }
end
else else
header[name] = value header[name] = value
end end