Bug #12055 ยป custom_content_range.patch
| lib/net/http/header.rb | ||
|---|---|---|
|
m[1].to_i .. m[2].to_i
|
||
|
end
|
||
|
def content_range_unit
|
||
|
return nil unless @header['content-range']
|
||
|
match = /(?<unit>\S+)\s/i.match(self['Content-Range'])
|
||
|
match[:unit]
|
||
|
end
|
||
|
# The length of the range represented in Content-Range: header.
|
||
|
def range_length
|
||
|
r = content_range() or return nil
|
||
| lib/net/http/response.rb | ||
|---|---|---|
|
def inflater # :nodoc:
|
||
|
return yield @socket unless Net::HTTP::HAVE_ZLIB
|
||
|
return yield @socket unless @decode_content
|
||
|
return yield @socket if self['content-range']
|
||
|
return yield @socket if content_range_unit == 'bytes'
|
||
|
v = self['content-encoding']
|
||
|
case v && v.downcase
|
||
| test/net/http/test_httpresponse.rb | ||
|---|---|---|
|
assert_equal "\x1F\x8B\b\x00\x00\x00\x00\x00\x00\x03", body
|
||
|
end
|
||
|
def test_read_body_content_encoding_ignore_custom_content_range
|
||
|
io = dummy_io(<<EOS)
|
||
|
HTTP/1.1 200 OK
|
||
|
Accept-Ranges: items
|
||
|
Content-Range: items 1-1/10
|
||
|
Content-Encoding: gzip
|
||
|
Connection: close
|
||
|
Transfer-Encoding: chunked
|
||
|
6
|
||
|
x\x9C\xCBH\xCD\xC9
|
||
|
7
|
||
|
\xC9\a\x00\x06,\x02\x15
|
||
|
0
|
||
|
EOS
|
||
|
res = Net::HTTPResponse.read_new(io)
|
||
|
res.decode_content = true
|
||
|
body = nil
|
||
|
res.reading_body io, true do
|
||
|
body = res.read_body
|
||
|
end
|
||
|
assert_equal 'hello', body
|
||
|
end
|
||
|
def test_read_body_content_encoding_deflate_empty_body
|
||
|
io = dummy_io(<<EOS)
|
||
|
HTTP/1.1 200 OK
|
||