From eea4dbb4379011dbb78d0a957836cff20dcebc51 Mon Sep 17 00:00:00 2001 From: Jackson Ray Hamilton Date: Fri, 7 Apr 2017 10:57:55 -0700 Subject: [PATCH] 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. --- lib/puma/server.rb | 2 +- test/test_puma_server.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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