* lib/webrick/httpservlet/filehandler.rb (make_partial_content):

add bytes-unit.  [ruby-dev:40030]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26346 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-01-18 08:16:07 +00:00
Родитель 9c54d38d60
Коммит f00951bb25
3 изменённых файлов: 73 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Mon Jan 18 17:16:03 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/webrick/httpservlet/filehandler.rb (make_partial_content):
add bytes-unit. [ruby-dev:40030]
Mon Jan 18 15:49:42 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/net/http.rb (Net::HTTPHeader#{content_range,range_length}):

Просмотреть файл

@ -87,7 +87,7 @@ module WEBrick
content = io.read(last-first+1)
body << "--" << boundary << CRLF
body << "Content-Type: #{mtype}" << CRLF
body << "Content-Range: #{first}-#{last}/#{filesize}" << CRLF
body << "Content-Range: bytes #{first}-#{last}/#{filesize}" << CRLF
body << CRLF
body << content
body << CRLF
@ -107,7 +107,7 @@ module WEBrick
content = io.read(last-first+1)
end
res['content-type'] = mtype
res['content-range'] = "#{first}-#{last}/#{filesize}"
res['content-range'] = "bytes #{first}-#{last}/#{filesize}"
res['content-length'] = last - first + 1
res.body = content
else

Просмотреть файл

@ -75,6 +75,11 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
def test_filehandler
config = { :DocumentRoot => File.dirname(__FILE__), }
this_file = File.basename(__FILE__)
filesize = File.size(__FILE__)
this_data = File.open(__FILE__, "rb") {|f| f.read}
range = nil
bug2593 = '[ruby-dev:40030]'
TestWEBrick.start_httpserver(config) do |server, addr, port, log|
http = Net::HTTP.new(addr, port)
req = Net::HTTP::Get.new("/")
@ -89,6 +94,67 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
assert_equal("text/plain", res.content_type, log.call)
assert_equal(File.read(__FILE__), res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=#{filesize-100}-")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal((filesize-100)..(filesize-1), range, log.call)
assert_equal(this_data[-100..-1], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=-100")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal((filesize-100)..(filesize-1), range, log.call)
assert_equal(this_data[-100..-1], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=0-99")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal(0..99, range, log.call)
assert_equal(this_data[0..99], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=100-199")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal(100..199, range, log.call)
assert_equal(this_data[100..199], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=0-0")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal(0..0, range, log.call)
assert_equal(this_data[0..0], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=-1")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("text/plain", res.content_type, log.call)
assert_nothing_raised(bug2593) {range = res.content_range}
assert_equal((filesize-1)..(filesize-1), range, log.call)
assert_equal(this_data[-1, 1], res.body, log.call)
}
req = Net::HTTP::Get.new("/#{this_file}", "range"=>"bytes=0-0, -2")
http.request(req){|res|
assert_equal("206", res.code, log.call)
assert_equal("multipart/byteranges", res.content_type, log.call)
}
end
end