diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-28 08:05:57 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-03-28 08:05:57 +0000 |
commit | 6360243fd2e385fbdc14eb5c62ae622ac2ea7021 (patch) | |
tree | 92ba2a4445675ee3de97c0f0556c178ee78db124 /lib/webrick/httpresponse.rb | |
parent | 2bdcd0bddea7de08b8845918ed27185fa3125734 (diff) | |
download | ruby-6360243fd2e385fbdc14eb5c62ae622ac2ea7021.tar.gz |
webrick: use IO.copy_stream for single range response
This is also compatible with range responses generated
by Rack::File (tested with rack 2.0.3).
* lib/webrick/httpresponse.rb (send_body_io): use Content-Range
* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
use File object for the single range case
* test/webrick/test_filehandler.rb (get_res_body): use send_body
to test result
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/httpresponse.rb')
-rw-r--r-- | lib/webrick/httpresponse.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb index 82c53e60c7..5b71facab6 100644 --- a/lib/webrick/httpresponse.rb +++ b/lib/webrick/httpresponse.rb @@ -410,9 +410,15 @@ module WEBrick buf.clear socket.write("0#{CRLF}#{CRLF}") else - size = @header['content-length'] - size = size.to_i if size - @sent_size = IO.copy_stream(@body, socket, size) + if %r{\Abytes (\d+)-(\d+)/\d+\z} =~ @header['content-range'] + offset = $1.to_i + size = $2.to_i - offset + 1 + else + offset = nil + size = @header['content-length'] + size = size.to_i if size + end + @sent_size = IO.copy_stream(@body, socket, size, offset) end ensure @body.close |