From 38d6b9e49eed43256f610afcf4389ba7d85054e0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Nov 2013 09:45:45 +0000 Subject: http: do not drop Content-Range from response headers We parse and use Content-Range, but do not drop it when sending a response since that would confuse clients. --- lib/yahns/http_response.rb | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') 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) -- cgit v1.2.3-24-ge0c7