about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2013-11-02 09:45:45 +0000
committerEric Wong <e@80x24.org>2013-11-02 09:45:45 +0000
commit38d6b9e49eed43256f610afcf4389ba7d85054e0 (patch)
tree5a189cdba84343040009e4ce4cd3ab3cdc008c1b
parent13a09dec6c029e01e8d959b0bf0feb94d72ae32d (diff)
downloadyahns-38d6b9e49eed43256f610afcf4389ba7d85054e0.tar.gz
We parse and use Content-Range, but do not drop it when sending
a response since that would confuse clients.
-rw-r--r--lib/yahns/http_response.rb17
-rw-r--r--test/test_serve_static.rb1
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