зеркало из https://github.com/github/ruby.git
HTTPHeader.content_range throws error on non-byte units
* Added a nil check in Net::HTTPHeader#initialize_http_header for keys in the header that do not have any value * Returning nil from the content_range method instead of raising an error when the unit in the content-range header is not bytes * Modified initialize_http_header to match trunk fix [Bug #11450] fix https://github.com/ruby/ruby/pull/1018
This commit is contained in:
Родитель
8ef312fc5b
Коммит
63546bfc15
|
@ -338,8 +338,8 @@ module Net::HTTPHeader
|
|||
# fits inside the full entity body, as range of byte offsets.
|
||||
def content_range
|
||||
return nil unless @header['content-range']
|
||||
m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range']) or
|
||||
raise Net::HTTPHeaderSyntaxError, 'wrong Content-Range format'
|
||||
m = %r<bytes\s+(\d+)-(\d+)/(\d+|\*)>i.match(self['Content-Range'])
|
||||
return nil if m.nil?
|
||||
m[1].to_i .. m[2].to_i
|
||||
end
|
||||
|
||||
|
|
|
@ -308,6 +308,14 @@ class HTTPHeaderTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_content_range
|
||||
@c['Content-Range'] = "bytes 0-499/1000"
|
||||
assert_equal 0..499, @c.content_range
|
||||
@c['Content-Range'] = "bytes 1-500/1000"
|
||||
assert_equal 1..500, @c.content_range
|
||||
@c['Content-Range'] = "bytes 1-1/1000"
|
||||
assert_equal 1..1, @c.content_range
|
||||
@c['Content-Range'] = "tokens 1-1/1000"
|
||||
assert_equal nil, @c.content_range
|
||||
end
|
||||
|
||||
def test_range_length
|
||||
|
@ -317,6 +325,8 @@ class HTTPHeaderTest < Test::Unit::TestCase
|
|||
assert_equal 500, @c.range_length
|
||||
@c['Content-Range'] = "bytes 1-1/1000"
|
||||
assert_equal 1, @c.range_length
|
||||
@c['Content-Range'] = "tokens 1-1/1000"
|
||||
assert_equal nil, @c.range_length
|
||||
end
|
||||
|
||||
def test_chunked?
|
||||
|
|
Загрузка…
Ссылка в новой задаче