Skip to content

Commit

Permalink
Merge pull request #7 from alex-eri/patch-1
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 98e2053 + 35c5817 commit c1ad3a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ CHANGES

- Fix StreamResponse representation after eof

- Fix file_sender to not fall on bad request (range out of file size)

- Fix file_sender to correct stream video to Chromes


1.3.3 (2017-02-19)
------------------
Expand Down
15 changes: 10 additions & 5 deletions aiohttp/file_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def send(self, request, filepath):
# 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 @@ -192,6 +191,8 @@ def send(self, request, filepath):
# 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

resp = self._response_factory(status=status)
resp.content_type = ct
Expand All @@ -201,10 +202,14 @@ def send(self, request, filepath):
resp.headers[hdrs.VARY] = hdrs.ACCEPT_ENCODING
resp.last_modified = st.st_mtime

if count != file_size:
status = HTTPPartialContent.status_code

resp.content_length = count
with filepath.open('rb') as f:
if start:
f.seek(start)
yield from self._sendfile(request, resp, f, count)
if count:
with filepath.open('rb') as f:
if start:
f.seek(start)
yield from self._sendfile(request, resp, f, count)

return resp

0 comments on commit c1ad3a7

Please sign in to comment.