From 409dd5d706ea347f0d70d2f8048bf4244a51efda Mon Sep 17 00:00:00 2001 From: alex-eri Date: Sun, 12 Mar 2017 16:19:23 +0300 Subject: [PATCH 1/2] fixes KeepSafe/aiohttp#1707 fixes KeepSafe/aiohttp#1595 - Fix file_sender to not fall on bad request (range out of file size) - Fix file_sender to correct stream video to Chromes --- aiohttp/web_fileresponse.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/aiohttp/web_fileresponse.py b/aiohttp/web_fileresponse.py index ec22e914042..12567199bc7 100644 --- a/aiohttp/web_fileresponse.py +++ b/aiohttp/web_fileresponse.py @@ -192,7 +192,6 @@ def prepare(self, request): # If a range request has been made, convert start, end slice notation # into file pointer offset and count if start is not None or end is not None: - status = HTTPPartialContent.status_code if start is None and end < 0: # return tail of file start = file_size + end count = -end @@ -208,7 +207,13 @@ def prepare(self, request): # value of last-byte-pos with a value that is one less than # the current length of the selected representation). count = file_size - start - + + if start >= file_size: + count = 0 + + if count != file_size: + status = HTTPPartialContent.status_code + self.set_status(status) self.content_type = ct if encoding: @@ -218,8 +223,9 @@ def prepare(self, request): self.last_modified = st.st_mtime self.content_length = count - with filepath.open('rb') as fobj: - if start: - fobj.seek(start) + if count: + with filepath.open('rb') as fobj: + if start: + fobj.seek(start) - return (yield from self._sendfile(request, fobj, count)) + return (yield from self._sendfile(request, fobj, count)) From 077a4259ea993d966bd0bf22b3ae7c16bd4000fe Mon Sep 17 00:00:00 2001 From: alex-eri Date: Sun, 12 Mar 2017 16:20:12 +0300 Subject: [PATCH 2/2] Update CHANGES.rst --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 8eceefebfb5..afc371fbef4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -61,3 +61,7 @@ CHANGES attributes and `resolve` constructor parameter #1607 - Dropped `ProxyConnector` #1609 + +- Fix file_sender to not fall on bad request (range out of file size) + +- Fix file_sender to correct stream video to Chromes