summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Renner Berthing <esmil@mailme.dk>2013-01-24 11:26:09 +0100
committerEmil Renner Berthing <esmil@mailme.dk>2013-01-24 22:03:28 +0100
commitbdb085de82231eb709058ffa78fbac6ff2df8c38 (patch)
tree903de6d619ec91d01a377f82c54a9c097420b6a2
parent4c264373c100af4cf9f3c350ad923d47135bb5c5 (diff)
downloadlem-bdb085de82231eb709058ffa78fbac6ff2df8c38.tar.gz
lem-bdb085de82231eb709058ffa78fbac6ff2df8c38.tar.xz
lem-bdb085de82231eb709058ffa78fbac6ff2df8c38.zip
http: header names are case-insensitive
..so make the parser lower-case header names
-rw-r--r--lem/http.lua16
-rw-r--r--lem/http/core.c24
-rw-r--r--lem/http/server.lua6
-rwxr-xr-xtest/htest.lua4
4 files changed, 27 insertions, 23 deletions
diff --git a/lem/http.lua b/lem/http.lua
index 8635bf9..dcdbd56 100644
--- a/lem/http.lua
+++ b/lem/http.lua
@@ -1,6 +1,6 @@
--
-- This file is part of LEM, a Lua Event Machine.
--- Copyright 2011-2012 Emil Renner Berthing
+-- Copyright 2011-2013 Emil Renner Berthing
--
-- LEM is free software: you can redistribute it and/or modify it
-- under the terms of the GNU Lesser General Public License as
@@ -32,13 +32,13 @@ local tonumber = tonumber
local concat = table.concat
function http.Request:body()
- local len, body = self.headers['Content-Length'], ''
+ local len, body = self.headers['content-length'], ''
if not len then return body end
len = tonumber(len)
if len <= 0 then return body end
- if self.headers['Expect'] == '100-continue' then
+ if self.headers['expect'] == '100-continue' then
local ok, err = self.client:send('HTTP/1.1 100 Continue\r\n\r\n')
if not ok then return nil, err end
end
@@ -75,17 +75,17 @@ function http.Response:body_chunked()
line, err = client:read('*l')
if not line then return nil, err end
- return t
+ return concat(t)
end
function http.Response:body()
- if self.headers['Transfer-Encoding'] == 'chunked' then
- return concat(self:body_chunked())
+ if self.headers['transfer-encoding'] == 'chunked' then
+ return self:body_chunked()
end
- local num = self.headers['Content-Length']
+ local num = self.headers['content-length']
if not num then
- if self.headers['Connection'] == 'close' then
+ if self.headers['connection'] == 'close' then
return self.client:read('*a')
end
return nil, 'no content length specified'
diff --git a/lem/http/core.c b/lem/http/core.c
index 3d4efc3..70f1327 100644
--- a/lem/http/core.c
+++ b/lem/http/core.c
@@ -1,6 +1,6 @@
/*
* This file is part of LEM, a Lua Event Machine.
- * Copyright 2011-2012 Emil Renner Berthing
+ * Copyright 2011-2013 Emil Renner Berthing
*
* LEM is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
@@ -206,11 +206,23 @@ parse_http_process(lua_State *T, struct lem_inputbuf *b)
case CMIV:
case CNUM:
case CTXT:
- case SKEY:
case SVAL:
b->buf[w++] = ch;
break;
+ case XKEY:
+ state = SKEY;
+ lua_pushlstring(T, b->buf, w);
+ lua_rawset(T, -3);
+ w = 0;
+ /* fallthrough */
+
+ case SKEY:
+ if (ch >= 'A' && ch <= 'Z')
+ ch += ('a' - 'A');
+ b->buf[w++] = ch;
+ break;
+
case SRE1:
lua_pushlstring(T, b->buf, w);
lua_setfield(T, -2, "version");
@@ -283,14 +295,6 @@ parse_http_process(lua_State *T, struct lem_inputbuf *b)
b->buf[w++] = ch;
break;
- case XKEY:
- state = SKEY;
- lua_pushlstring(T, b->buf, w);
- lua_rawset(T, -3);
- w = 0;
- b->buf[w++] = ch;
- break;
-
case XEND:
/* in case there are no headers this is false */
if (lua_type(T, -1) == LUA_TSTRING) {
diff --git a/lem/http/server.lua b/lem/http/server.lua
index e6cb088..119d1d9 100644
--- a/lem/http/server.lua
+++ b/lem/http/server.lua
@@ -110,7 +110,7 @@ local status_string = {
M.status_string = status_string
function M.not_found(req, res)
- if req.headers['Expect'] ~= '100-continue' then
+ if req.headers['expect'] ~= '100-continue' then
req:body()
end
@@ -212,7 +212,7 @@ do
M.version_not_supported(req, res)
version = '1.1'
else
- local expect = req.headers['Expect']
+ local expect = req.headers['expect']
if expect and expect ~= '100-continue' then
M.expectation_failed(req, res)
else
@@ -264,7 +264,7 @@ do
headers['Server'] = 'Hathaway/0.1 LEM/0.3'
end
- if req.headers['Connection'] == 'close' and headers['Connection'] == nil then
+ if req.headers['connection'] == 'close' and headers['Connection'] == nil then
headers['Connection'] = 'close'
end
diff --git a/test/htest.lua b/test/htest.lua
index ac54489..2be8e6c 100755
--- a/test/htest.lua
+++ b/test/htest.lua
@@ -40,7 +40,7 @@ GET('/self', function(req, res)
end)
GET('/dump', function(req, res)
- local accept = req.headers['Accept']
+ local accept = req.headers['accept']
if accept and accept:match('application/xhtml%+xml') then
res.headers['Content-Type'] = 'application/xhtml+xml'
else
@@ -129,7 +129,7 @@ end)
POST('/quit', function(req, res)
local body = req:body()
- req.headers['Content-Type'] = 'text/plain'
+ res.headers['Content-Type'] = 'text/plain'
if body == 'quit=secret' then
res:add("Bye o/\n")