diff --git a/lib/puma/server.rb b/lib/puma/server.rb index 4c102b3e..f1603f8f 100644 --- a/lib/puma/server.rb +++ b/lib/puma/server.rb @@ -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 diff --git a/test/test_puma_server.rb b/test/test_puma_server.rb index af5375d6..7e43d9c6 100644 --- a/test/test_puma_server.rb +++ b/test/test_puma_server.rb @@ -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