1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Don't omit empty header values. (#1261)

* Don't omit empty header values.

''.split => [] so no header would be appended.

* Add test for empty header values.
This commit is contained in:
Jackson Ray Hamilton 2017-04-07 10:57:55 -07:00 committed by Nate Berkopec
parent de870595d0
commit eea4dbb437
2 changed files with 16 additions and 1 deletions

View file

@ -689,7 +689,7 @@ module Puma
next
end
if vs.respond_to?(:to_s)
if vs.respond_to?(:to_s) && !vs.to_s.empty?
vs.to_s.split(NEWLINE).each do |v|
lines.append k, colon, v, line_ending
end

View file

@ -623,4 +623,19 @@ class TestPumaServer < Minitest::Test
assert_equal "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 0\r\n\r\n", data
assert_equal "hello", body
end
def test_empty_header_values
@server.app = proc { |env| [200, {"X-Empty-Header" => ""}, []] }
@server.add_tcp_listener @host, @port
@server.run
sock = TCPSocket.new @host, @server.connected_port
sock << "HEAD / HTTP/1.0\r\n\r\n"
data = sock.read
assert_equal "HTTP/1.0 200 OK\r\nX-Empty-Header: \r\n\r\n", data
end
end