Skip to content

Commit

Permalink
Added an probably unnecessay header: Content-Range when HTTP 416 is r…
Browse files Browse the repository at this point in the history
…eturned
  • Loading branch information
spcharc committed Mar 19, 2018
1 parent e751ebe commit 577c81a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions aiohttp/web_fileresponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,17 @@ async def prepare(self, request):
start = rng.start
end = rng.stop
except ValueError:
# https://tools.ietf.org/html/rfc7233:
# A server generating a 416 (Range Not Satisfiable) response to
# a byte-range request SHOULD send a Content-Range header field
# with an unsatisfied-range value.
# The complete-length in a 416 response indicates the current
# length of the selected representation.
#
# Will do the same below. Many servers ignore this and do not
# send a Content-Range header with HTTP 416
self.headers[hdrs.CONTENT_RANGE] = 'bytes */{0}'.format(
file_size)
self.set_status(HTTPRequestRangeNotSatisfiable.status_code)
return await super().prepare(request)

Expand Down Expand Up @@ -238,6 +249,8 @@ async def prepare(self, request):
# suffix-byte-range-spec with a non-zero suffix-length,
# then the byte-range-set is satisfiable. Otherwise, the
# byte-range-set is unsatisfiable.
self.headers[hdrs.CONTENT_RANGE] = 'bytes */{0}'.format(
file_size)
self.set_status(HTTPRequestRangeNotSatisfiable.status_code)
return await super().prepare(request)

Expand Down

0 comments on commit 577c81a

Please sign in to comment.