Skip to content

Commit ae153ab

Browse files
[PR #10107/84bb77d1 backport][3.11] Use internal self._headers var in FileResponse (#10108)
Co-authored-by: J. Nick Koston <nick@koston.org>
1 parent 07d1759 commit ae153ab

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

aiohttp/web_fileresponse.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ async def _prepare_open_file(
315315
#
316316
# Will do the same below. Many servers ignore this and do not
317317
# send a Content-Range header with HTTP 416
318-
self.headers[hdrs.CONTENT_RANGE] = f"bytes */{file_size}"
318+
self._headers[hdrs.CONTENT_RANGE] = f"bytes */{file_size}"
319319
self.set_status(HTTPRequestRangeNotSatisfiable.status_code)
320320
return await super().prepare(request)
321321

@@ -351,7 +351,7 @@ async def _prepare_open_file(
351351
# suffix-byte-range-spec with a non-zero suffix-length,
352352
# then the byte-range-set is satisfiable. Otherwise, the
353353
# byte-range-set is unsatisfiable.
354-
self.headers[hdrs.CONTENT_RANGE] = f"bytes */{file_size}"
354+
self._headers[hdrs.CONTENT_RANGE] = f"bytes */{file_size}"
355355
self.set_status(HTTPRequestRangeNotSatisfiable.status_code)
356356
return await super().prepare(request)
357357

@@ -363,16 +363,16 @@ async def _prepare_open_file(
363363
# If the Content-Type header is not already set, guess it based on the
364364
# extension of the request path. The encoding returned by guess_type
365365
# can be ignored since the map was cleared above.
366-
if hdrs.CONTENT_TYPE not in self.headers:
366+
if hdrs.CONTENT_TYPE not in self._headers:
367367
if sys.version_info >= (3, 13):
368368
guesser = CONTENT_TYPES.guess_file_type
369369
else:
370370
guesser = CONTENT_TYPES.guess_type
371371
self.content_type = guesser(self._path)[0] or FALLBACK_CONTENT_TYPE
372372

373373
if file_encoding:
374-
self.headers[hdrs.CONTENT_ENCODING] = file_encoding
375-
self.headers[hdrs.VARY] = hdrs.ACCEPT_ENCODING
374+
self._headers[hdrs.CONTENT_ENCODING] = file_encoding
375+
self._headers[hdrs.VARY] = hdrs.ACCEPT_ENCODING
376376
# Disable compression if we are already sending
377377
# a compressed file since we don't want to double
378378
# compress.
@@ -382,12 +382,12 @@ async def _prepare_open_file(
382382
self.last_modified = st.st_mtime # type: ignore[assignment]
383383
self.content_length = count
384384

385-
self.headers[hdrs.ACCEPT_RANGES] = "bytes"
385+
self._headers[hdrs.ACCEPT_RANGES] = "bytes"
386386

387387
real_start = cast(int, start)
388388

389389
if status == HTTPPartialContent.status_code:
390-
self.headers[hdrs.CONTENT_RANGE] = "bytes {}-{}/{}".format(
390+
self._headers[hdrs.CONTENT_RANGE] = "bytes {}-{}/{}".format(
391391
real_start, real_start + count - 1, file_size
392392
)
393393

0 commit comments

Comments
 (0)