Skip to content

Instantly share code, notes, and snippets.

@dbishop
Created September 9, 2012 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbishop/3681877 to your computer and use it in GitHub Desktop.
Save dbishop/3681877 to your computer and use it in GitHub Desktop.
This patch to webob.byterange fixes "Range: bytes=-17" for Content-Length < 17 (eg. 10 in my tests).
diff --git a/test/functional/tests.py b/test/functional/tests.py
index dd589e6..cd734ac 100644
--- a/test/functional/tests.py
+++ b/test/functional/tests.py
@@ -1147,6 +1147,13 @@ class TestFile(Base):
hdrs = {'Range': '0-4'}
self.assert_(file.read(hdrs=hdrs) == data, range_string)
+ # "If the entity is shorter than the specified suffix-length, the
+ # entire entity-body is used."
+ range_string = 'bytes=-%d' % (file_length + 10)
+ hdrs = {'Range': range_string}
+ self.assert_(file.read(hdrs=hdrs) == data, range_string)
+
+
def testRangedGetsWithLWSinHeader(self):
#Skip this test until webob 1.2 can tolerate LWS in Range header.
from webob.byterange import Range
swiftstack@saio:~/swift/swift/obj$ diff -u /usr/share/pyshared/webob/byterange.py.orig /usr/share/pyshared/webob/byterange.py
--- /usr/share/pyshared/webob/byterange.py.orig 2012-09-07 16:48:30.996446789 -0700
+++ /usr/share/pyshared/webob/byterange.py 2012-09-07 17:00:40.188476542 -0700
@@ -36,7 +36,7 @@
if end is None:
end = length
if start < 0:
- start += length
+ start = max(0, start + length)
if _is_content_range_valid(start, end, length):
stop = min(end, length)
return (start, stop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment