Project

General

Profile

Actions

Bug #11450

closed

HTTPHeader.content_range throws error on non-byte units

Added by thomthom (Thomas Thomassen) over 8 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:<unknown>]
Tags:

Description

I ran into an issue with HTTPHeader.content_range today when interacting with an REST API that used Range and Content-Range with units other than "bytes". It used "items" instead to let the API user to say how many data items should be returned from the database.

The HTTP 1.1 specs only define "bytes", but other units are valid (see that "other-range-unit" is described). The specs then say implementations might ignore these other units. However, Ruby doesn't ignore - Ruby throws an error and refuse to proceed.

https://www.ietf.org/rfc/rfc2616.txt

3.12 Range Units

HTTP/1.1 allows a client to request that only part (a range of) the
response entity be included within the response. HTTP/1.1 uses range
units in the Range (section 14.35) and Content-Range (section 14.16)
header fields. An entity can be broken down into subranges according
to various structural units.

range-unit = bytes-unit | other-range-unit
bytes-unit = "bytes"
other-range-unit = token

The only range unit defined by HTTP/1.1 is "bytes". HTTP/1.1
implementations MAY ignore ranges specified using other units.

Looking at the source it can be seen that "bytes" is hard coded and Ruby doesn't account for the possibility of any other unit.

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[1].to_i .. m[2].to_i
end

The best thing would be if Ruby handled custom range units, but in the very least ignored unknown units instead of throwing errors for a valid HTTP response with custom range units.


Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #12055: `NET::HTTPResponse` is not deflating responses with custom `Content-Range` headerClosednaruse (Yui NARUSE)Actions
Actions #1

Updated by shishir127 (Shishir Joshi) over 8 years ago

Raised a PR

Actions #2

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Has duplicate Bug #12055: `NET::HTTPResponse` is not deflating responses with custom `Content-Range` header added
Actions #3

Updated by Anonymous almost 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|63546bfc1581d4abec2a0d846106a1c0afc0efa9.


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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0