ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:70425] [Ruby trunk - Bug #11450] [Open] HTTPHeader.content_range throws error on non-byte units
       [not found] <redmine.issue-11450.20150817121209@ruby-lang.org>
@ 2015-08-17 12:12 ` thomas
  2015-09-29 12:50 ` [ruby-core:70947] [Ruby trunk - Bug #11450] " shishir127
  1 sibling, 0 replies; 2+ messages in thread
From: thomas @ 2015-08-17 12:12 UTC (permalink / raw
  To: ruby-core

Issue #11450 has been reported by Thomas Thomassen.

----------------------------------------
Bug #11450: HTTPHeader.content_range throws error on non-byte units
https://bugs.ruby-lang.org/issues/11450

* Author: Thomas Thomassen
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.0 to 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
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.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [ruby-core:70947] [Ruby trunk - Bug #11450] HTTPHeader.content_range throws error on non-byte units
       [not found] <redmine.issue-11450.20150817121209@ruby-lang.org>
  2015-08-17 12:12 ` [ruby-core:70425] [Ruby trunk - Bug #11450] [Open] HTTPHeader.content_range throws error on non-byte units thomas
@ 2015-09-29 12:50 ` shishir127
  1 sibling, 0 replies; 2+ messages in thread
From: shishir127 @ 2015-09-29 12:50 UTC (permalink / raw
  To: ruby-core

Issue #11450 has been updated by Shishir Joshi.


Raised a [PR](https://github.com/ruby/ruby/pull/1018)

----------------------------------------
Bug #11450: HTTPHeader.content_range throws error on non-byte units
https://bugs.ruby-lang.org/issues/11450#change-54311

* Author: Thomas Thomassen
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 2.0 to 2.2
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
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.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-29 12:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-11450.20150817121209@ruby-lang.org>
2015-08-17 12:12 ` [ruby-core:70425] [Ruby trunk - Bug #11450] [Open] HTTPHeader.content_range throws error on non-byte units thomas
2015-09-29 12:50 ` [ruby-core:70947] [Ruby trunk - Bug #11450] " shishir127

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).