Skip to content

Commit

Permalink
Merge pull request #8 from alex-eri/patch-2
Browse files Browse the repository at this point in the history
serving a static mp4 file caused exception #1595
  • Loading branch information
fafhrd91 authored Mar 13, 2017
2 parents 1a3723e + 077a425 commit be13847
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 12 additions & 6 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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))

0 comments on commit be13847

Please sign in to comment.