Use http.HTTPStatus in components/s* (#58291)

This commit is contained in:
Ville Skyttä 2021-10-23 21:49:04 +03:00 committed by GitHub
parent 05671557f0
commit 50e0c58310
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 180 additions and 158 deletions

View file

@ -1,6 +1,7 @@
"""Provide functionality to stream HLS."""
from __future__ import annotations
from http import HTTPStatus
from typing import TYPE_CHECKING, cast
from aiohttp import web
@ -193,7 +194,7 @@ class HlsPlaylistView(StreamView):
"""Return a HTTP Bad Request response."""
return web.Response(
body=None,
status=400,
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
@ -211,7 +212,7 @@ class HlsPlaylistView(StreamView):
"""Return a HTTP Not Found response."""
return web.Response(
body=None,
status=404,
status=HTTPStatus.NOT_FOUND,
headers={
"Cache-Control": f"max-age={(4 if blocking else 1)*target_duration:.0f}"
},
@ -351,7 +352,7 @@ class HlsPartView(StreamView):
):
return web.Response(
body=None,
status=404,
status=HTTPStatus.NOT_FOUND,
headers={"Cache-Control": f"max-age={track.target_duration:.0f}"},
)
# If the part is ready or has been hinted,
@ -399,7 +400,7 @@ class HlsSegmentView(StreamView):
):
return web.Response(
body=None,
status=404,
status=HTTPStatus.NOT_FOUND,
headers={"Cache-Control": f"max-age={track.target_duration:.0f}"},
)
return web.Response(