diff --git a/swift/common/swob.py b/swift/common/swob.py index 1a8c6ea630..900767dbbe 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -467,6 +467,8 @@ class Range(object): :param headerval: value of the header as a str """ def __init__(self, headerval): + if not headerval: + raise ValueError('Invalid Range header: %r' % headerval) headerval = headerval.replace(' ', '') if not headerval.lower().startswith('bytes='): raise ValueError('Invalid Range header: %s' % headerval) diff --git a/swift/proxy/controllers/base.py b/swift/proxy/controllers/base.py index 36b98f484e..2bc1ef2718 100644 --- a/swift/proxy/controllers/base.py +++ b/swift/proxy/controllers/base.py @@ -1061,6 +1061,7 @@ class ResumingGetter(object): self.app.client_timeout) self.app.logger.increment('client_timeouts') except GeneratorExit: + exc_type, exc_value, exc_traceback = exc_info() warn = True try: req_range = Range(self.backend_headers['Range']) @@ -1068,11 +1069,12 @@ class ResumingGetter(object): req_range = None if req_range and len(req_range.ranges) == 1: begin, end = req_range.ranges[0] - if end - begin + 1 == self.bytes_used_from_backend: - warn = False + if end is not None and begin is not None: + if end - begin + 1 == self.bytes_used_from_backend: + warn = False if not req.environ.get('swift.non_client_disconnect') and warn: self.app.logger.warning(_('Client disconnected on read')) - raise + six.reraise(exc_type, exc_value, exc_traceback) except Exception: self.app.logger.exception(_('Trying to send to client')) raise diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index f1a11e1fcb..c4b1797c52 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -249,6 +249,7 @@ class TestRange(unittest.TestCase): 6. any combination of the above """ + _assert_invalid_range(None) _assert_invalid_range('nonbytes=foobar,10-2') _assert_invalid_range('bytes=5-3') _assert_invalid_range('bytes=-')