Skip to content
This repository
Browse code

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.
  • Loading branch information...
commit 6f1ff378af588e274c8b4f6ba99159695f966e75 1 parent f089985
Pete Zaitcev zaitcev authored

Showing 2 changed files with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. +1 0  tests/test_byterange.py
  2. +1 1  webob/byterange.py
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):

0 comments on commit 6f1ff37

Please sign in to comment.
Something went wrong with that request. Please try again.