diff --git a/src/calibre/srv/respond.py b/src/calibre/srv/respond.py index a8ba4c191d..3f80b10aa7 100644 --- a/src/calibre/srv/respond.py +++ b/src/calibre/srv/respond.py @@ -47,6 +47,7 @@ def get_ranges(headervalue, content_length): continue if stop < start: continue + stop = min(stop, content_length - 1) result.append(Range(start, stop, stop - start + 1)) elif stop: # Negative subscript (last N bytes) diff --git a/src/calibre/srv/tests/http.py b/src/calibre/srv/tests/http.py index 1cb873bb38..c78631172a 100644 --- a/src/calibre/srv/tests/http.py +++ b/src/calibre/srv/tests/http.py @@ -241,6 +241,10 @@ class TestHTTP(BaseTest): self.ae(type('')(r.getheader('Content-Range')), 'bytes */%d' % len(fdata)) self.ae(r.status, httplib.REQUESTED_RANGE_NOT_SATISFIABLE) + conn.request('GET', '/test', headers={'Range':'bytes=0-1000000'}) + r = conn.getresponse() + self.ae(r.status, httplib.PARTIAL_CONTENT), self.ae(r.read(), fdata) + conn.request('GET', '/test', headers={'Range':'bytes=25-50', 'If-Range':etag}) r = conn.getresponse() self.ae(int(r.getheader('Content-Length')), 26)