Skip to content
This repository

Make the "bytes=" unit case-insensitive in Range header #62

Merged
merged 1 commit into from almost 2 years ago

2 participants

Pete Zaitcev Sergey Schetinin
Pete Zaitcev

I was unable to find any clear guidance in RFC-2616 or elsewhere.
It looks like they simply forgot to mention if token called
"bytes-unit" is case-sensitive or not. Generally fields are
not sensitive, but there are exceptions. Certainly, it is valid
to accept extra units, if we deem "bytes=" and "BYTES=" different.

This patch came about because OpenStack Swift throws an exception
on WebOb 1.2. It worked in WebOb 1.0.8, where we had a code that
invoked .lower() before matching.

Pete Zaitcev Make the "bytes=" unit case-insensitive in Range header
I was unable to find any clear guidance in RFC-2616 or elsewhere.
It looks like they simply forgot to mention if token called
"bytes-unit" is case-sensitive or not. Generally fields are
not sensitive, but there are exceptions. Certainly, it is valid
to accept extra units, if we deem "bytes=" and "BYTES=" different.

This patch came about because OpenStack Swift throws an exception
on WebOb 1.2. It worked in WebOb 1.0.8, where we had a code that
invoked .lower() before matching.
6f1ff37
Sergey Schetinin maluke merged commit 4bb9375 into from July 12, 2012
Sergey Schetinin maluke closed this July 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 11, 2012
Pete Zaitcev Make the "bytes=" unit case-insensitive in Range header
I was unable to find any clear guidance in RFC-2616 or elsewhere.
It looks like they simply forgot to mention if token called
"bytes-unit" is case-sensitive or not. Generally fields are
not sensitive, but there are exceptions. Certainly, it is valid
to accept extra units, if we deem "bytes=" and "BYTES=" different.

This patch came about because OpenStack Swift throws an exception
on WebOb 1.2. It worked in WebOb 1.0.8, where we had a code that
invoked .lower() before matching.
6f1ff37
This page is out of date. Refresh to see the latest.
1  tests/test_byterange.py
@@ -14,6 +14,7 @@ def test_not_satisfiable():
14 14
 
15 15
 def test_range_parse():
16 16
     assert isinstance(Range.parse('bytes=0-99'), Range)
  17
+    assert isinstance(Range.parse('BYTES=0-99'), Range)
17 18
     assert isinstance(Range.parse('bytes = 0-99'), Range)
18 19
     assert isinstance(Range.parse('bytes=0 - 102'), Range)
19 20
     assert Range.parse('bytes=10-5') is None
2  webob/byterange.py
@@ -2,7 +2,7 @@
2 2
 
3 3
 __all__ = ['Range', 'ContentRange']
4 4
 
5  
-_rx_range = re.compile('bytes *= *(\d*) *- *(\d*)')
  5
+_rx_range = re.compile('bytes *= *(\d*) *- *(\d*)', flags=re.I)
6 6
 _rx_content_range = re.compile(r'bytes (?:(\d+)-(\d+)|[*])/(?:(\d+)|[*])')
7 7
 
8 8
 class Range(object):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.