mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Remove cache control headers from stream (#71996)
This commit is contained in:
parent
f965f542a3
commit
c2612d1ade
@ -215,16 +215,6 @@ class HlsPlaylistView(StreamView):
|
|||||||
return web.Response(
|
return web.Response(
|
||||||
body=None,
|
body=None,
|
||||||
status=HTTPStatus.BAD_REQUEST,
|
status=HTTPStatus.BAD_REQUEST,
|
||||||
# From Appendix B.1 of the RFC:
|
|
||||||
# Successful responses to blocking Playlist requests should be cached
|
|
||||||
# for six Target Durations. Unsuccessful responses (such as 404s) should
|
|
||||||
# be cached for four Target Durations. Successful responses to non-blocking
|
|
||||||
# Playlist requests should be cached for half the Target Duration.
|
|
||||||
# Unsuccessful responses to non-blocking Playlist requests should be
|
|
||||||
# cached for for one Target Duration.
|
|
||||||
headers={
|
|
||||||
"Cache-Control": f"max-age={(4 if blocking else 1)*target_duration:.0f}"
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -233,9 +223,6 @@ class HlsPlaylistView(StreamView):
|
|||||||
return web.Response(
|
return web.Response(
|
||||||
body=None,
|
body=None,
|
||||||
status=HTTPStatus.NOT_FOUND,
|
status=HTTPStatus.NOT_FOUND,
|
||||||
headers={
|
|
||||||
"Cache-Control": f"max-age={(4 if blocking else 1)*target_duration:.0f}"
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
async def handle(
|
async def handle(
|
||||||
@ -318,7 +305,6 @@ class HlsPlaylistView(StreamView):
|
|||||||
body=self.render(track).encode("utf-8"),
|
body=self.render(track).encode("utf-8"),
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": FORMAT_CONTENT_TYPE[HLS_PROVIDER],
|
"Content-Type": FORMAT_CONTENT_TYPE[HLS_PROVIDER],
|
||||||
"Cache-Control": f"max-age={(6 if blocking_request else 0.5)*track.target_duration:.0f}",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
response.enable_compression(web.ContentCoding.gzip)
|
response.enable_compression(web.ContentCoding.gzip)
|
||||||
@ -373,22 +359,16 @@ class HlsPartView(StreamView):
|
|||||||
return web.Response(
|
return web.Response(
|
||||||
body=None,
|
body=None,
|
||||||
status=HTTPStatus.NOT_FOUND,
|
status=HTTPStatus.NOT_FOUND,
|
||||||
headers={"Cache-Control": f"max-age={track.target_duration:.0f}"},
|
|
||||||
)
|
)
|
||||||
# If the part is ready or has been hinted,
|
# If the part is ready or has been hinted,
|
||||||
if int(part_num) == len(segment.parts):
|
if int(part_num) == len(segment.parts):
|
||||||
await track.part_recv(timeout=track.stream_settings.hls_part_timeout)
|
await track.part_recv(timeout=track.stream_settings.hls_part_timeout)
|
||||||
if int(part_num) >= len(segment.parts):
|
if int(part_num) >= len(segment.parts):
|
||||||
return web.HTTPRequestRangeNotSatisfiable(
|
return web.HTTPRequestRangeNotSatisfiable()
|
||||||
headers={
|
|
||||||
"Cache-Control": f"max-age={track.target_duration:.0f}",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return web.Response(
|
return web.Response(
|
||||||
body=segment.parts[int(part_num)].data,
|
body=segment.parts[int(part_num)].data,
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": "video/iso.segment",
|
"Content-Type": "video/iso.segment",
|
||||||
"Cache-Control": f"max-age={6*track.target_duration:.0f}",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -421,12 +401,10 @@ class HlsSegmentView(StreamView):
|
|||||||
return web.Response(
|
return web.Response(
|
||||||
body=None,
|
body=None,
|
||||||
status=HTTPStatus.NOT_FOUND,
|
status=HTTPStatus.NOT_FOUND,
|
||||||
headers={"Cache-Control": f"max-age={track.target_duration:.0f}"},
|
|
||||||
)
|
)
|
||||||
return web.Response(
|
return web.Response(
|
||||||
body=segment.get_data(),
|
body=segment.get_data(),
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": "video/iso.segment",
|
"Content-Type": "video/iso.segment",
|
||||||
"Cache-Control": f"max-age={6*track.target_duration:.0f}",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -176,7 +176,7 @@ class HLSSync:
|
|||||||
self.check_requests_ready()
|
self.check_requests_ready()
|
||||||
return self._original_not_found()
|
return self._original_not_found()
|
||||||
|
|
||||||
def response(self, body, headers, status=HTTPStatus.OK):
|
def response(self, body, headers=None, status=HTTPStatus.OK):
|
||||||
"""Intercept the Response call so we know when the web handler is finished."""
|
"""Intercept the Response call so we know when the web handler is finished."""
|
||||||
self._num_finished += 1
|
self._num_finished += 1
|
||||||
self.check_requests_ready()
|
self.check_requests_ready()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user