mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Fix sending Content-Type and Content-Length for no body status. Fixes #304
This commit is contained in:
parent
858917a8a6
commit
f7f7733861
2 changed files with 24 additions and 5 deletions
|
@ -443,8 +443,6 @@ module Puma
|
|||
when TRANSFER_ENCODING
|
||||
allow_chunked = false
|
||||
content_length = nil
|
||||
when CONTENT_TYPE
|
||||
next if no_body
|
||||
when HIJACK
|
||||
response_hijack = vs
|
||||
next
|
||||
|
@ -456,6 +454,10 @@ module Puma
|
|||
end
|
||||
|
||||
if no_body
|
||||
if content_length and status != 204
|
||||
lines.append CONTENT_LENGTH_S, content_length.to_s, line_ending
|
||||
end
|
||||
|
||||
lines << line_ending
|
||||
fast_write client, lines.to_s
|
||||
return keep_alive
|
||||
|
|
|
@ -174,7 +174,7 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
|
||||
data = sock.read
|
||||
|
||||
assert_equal "HTTP/1.0 200 OK\r\nFoo: Bar\r\n\r\n", data
|
||||
assert_equal "HTTP/1.0 200 OK\r\nFoo: Bar\r\nContent-Length: 5\r\n\r\n", data
|
||||
end
|
||||
|
||||
def test_GET_with_empty_body_has_sane_chunking
|
||||
|
@ -188,11 +188,11 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
|
||||
data = sock.read
|
||||
|
||||
assert_equal "HTTP/1.0 200 OK\r\n\r\n", data
|
||||
assert_equal "HTTP/1.0 200 OK\r\nContent-Length: 0\r\n\r\n", data
|
||||
end
|
||||
|
||||
def test_GET_with_no_body_has_sane_chunking
|
||||
@server.app = proc { |env| [200, {}, [""]] }
|
||||
@server.app = proc { |env| [200, {}, []] }
|
||||
|
||||
@server.add_tcp_listener @host, @port
|
||||
@server.run
|
||||
|
@ -229,6 +229,7 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
@server.run
|
||||
|
||||
sock = TCPSocket.new @host, @port
|
||||
|
||||
sock << "GET / HTTP/1.0\r\n\r\n"
|
||||
|
||||
data = sock.read
|
||||
|
@ -249,4 +250,20 @@ class TestPumaServer < Test::Unit::TestCase
|
|||
|
||||
assert_equal "HTTP/1.1 449 CUSTOM\r\nContent-Length: 0\r\n\r\n", data
|
||||
end
|
||||
|
||||
def test_HEAD_returns_content_headers
|
||||
@server.app = proc { |env| [200, {"Content-Type" => "application/pdf",
|
||||
"Content-Length" => "4242"}, []] }
|
||||
|
||||
@server.add_tcp_listener @host, @port
|
||||
@server.run
|
||||
|
||||
sock = TCPSocket.new @host, @port
|
||||
|
||||
sock << "HEAD / HTTP/1.0\r\n\r\n"
|
||||
|
||||
data = sock.read
|
||||
|
||||
assert_equal "HTTP/1.0 200 OK\r\nContent-Type: application/pdf\r\nContent-Length: 4242\r\n\r\n", data
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue