diff options
-rw-r--r-- | lib/yahns/http_response.rb | 17 | ||||
-rw-r--r-- | test/test_serve_static.rb | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index f48b4d8..1b9478f 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -93,6 +93,15 @@ module Yahns::HttpResponse # :nodoc: end end + def kv_str(key, value) + if value =~ /\n/ + # avoiding blank, key-only cookies with /\n+/ + value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" }.join + else + "#{key}: #{value}\r\n" + end + end + # writes the rack_response to socket as an HTTP response # returns :wait_readable, :wait_writable, :forget, or nil def http_response_write(status, headers, body) @@ -113,6 +122,7 @@ module Yahns::HttpResponse # :nodoc: offset = $1.to_i count = $2.to_i - offset + 1 end + buf << kv_str(key, value) when %r{\AConnection\z}i # allow Rack apps to tell us they want to drop the client alive = !!(value =~ /\bclose\b/i) @@ -120,12 +130,7 @@ module Yahns::HttpResponse # :nodoc: hijack = value body = nil # ensure we do not close body else - if value =~ /\n/ - # avoiding blank, key-only cookies with /\n+/ - buf << value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" }.join - else - buf << "#{key}: #{value}\r\n" - end + buf << kv_str(key, value) end end buf << (alive ? CONN_KA : CONN_CLOSE) diff --git a/test/test_serve_static.rb b/test/test_serve_static.rb index 4f33b6f..edd700c 100644 --- a/test/test_serve_static.rb +++ b/test/test_serve_static.rb @@ -32,6 +32,7 @@ class TestServeStatic < Testcase req = Net::HTTP::Get.new("/COPYING", "Range" => "bytes=5-46") res = http.request(req) + assert_match %r{bytes 5-46/\d+\z}, res["Content-Range"] assert_equal gplv3[5..46], res.body end |