Skip to content

Commit 6047fca

Browse files
committed
Don't ignore headers when replying with a custom status.
If you reply a request with a custom status line and headers, those are ignored. fixes #14
1 parent 83aca40 commit 6047fca

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

lib/luanode/http.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ end
593593
--
594594
--
595595
function ServerResponse:writeHead (statusCode, reasonPhrase, headers)
596-
local headers, headerIndex
596+
local headerIndex
597597

598598
if type(reasonPhrase) == "table" then
599599
headers = reasonPhrase

test/simple/test-http-issue_14.lua

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
-- Test for https://github.com/ignacio/LuaNode/issues/14
3+
--
4+
-- response:writeHead with a status reason ignores headers
5+
--
6+
7+
module(..., lunit.testcase, package.seeall)
8+
9+
local common = dofile "common.lua"
10+
local http = require "luanode.http"
11+
12+
function test()
13+
14+
local server = http.createServer(function(self, req, res)
15+
res:writeHead(200, "Some custom status", {["Content-Type"] = "text/plain"})
16+
res:finish("hello there")
17+
self:close()
18+
end)
19+
20+
21+
server:listen(common.PORT, function ()
22+
local client = http.createClient(common.PORT)
23+
local request = client:request("GET", "/")
24+
request:finish()
25+
request:on("response", function (self, response)
26+
assert_equal(response.headers["content-type"], "text/plain")
27+
end)
28+
end)
29+
30+
process:loop()
31+
end

0 commit comments

Comments
 (0)