Skip to content

Commit

Permalink
fix(headers) tabs are allowed, and whitespace must be trimmed
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Feb 19, 2023
1 parent b8fe100 commit bcc4848
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion spec/unit/request_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('require', function()

test('headers', function()
local request = getInstance(
{ 'GET /Makefile?a=b&c=d&e=1&e=2 HTTP/1.1', 'a: A', 'b: B', 'c: X', 'c: Y', '', 'C=3', '' }
{ 'GET /Makefile?a=b&c=d&e=1&e=2 HTTP/1.1', 'a:A', 'b: \t B \t ', 'c: X', 'c: Y', '', 'C=3', '' }
)

assert.are.same(
Expand Down
3 changes: 2 additions & 1 deletion src/pegasus/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Request.PATTERN_PROTOCOL = '(HTTP%/%d%.%d)'
Request.PATTERN_REQUEST = (Request.PATTERN_METHOD ..
Request.PATTERN_PATH ..Request.PATTERN_PROTOCOL)
Request.PATTERN_QUERY_STRING = '([^=]*)=([^&]*)&?'
Request.PATTERN_HEADER = '([%w-]+): ([%w %p]+=?)'
Request.PATTERN_HEADER = '([%w-]+):[ \t]*([%w \t%p]*)'

function Request:new(port, client, server)
local obj = {}
Expand Down Expand Up @@ -142,6 +142,7 @@ function Request:headers()
local key, value = string.match(data, Request.PATTERN_HEADER)

if key and value then
value = value:gsub("%s+$", "") -- trim trailing whitespace
local v = headers[key]
if not v then
headers[key] = value
Expand Down

0 comments on commit bcc4848

Please sign in to comment.