Skip to content

Commit

Permalink
Fix streaming header & status issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mhdzumair committed Aug 25, 2024
1 parent 6ea5eed commit 8013acb
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
6 changes: 0 additions & 6 deletions mediaflow_proxy/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
"etag",
"server",
"date",
"cache-control",
"expires",
"pragma",
"content-disposition",
"range",
"content-encoding",
]

SUPPORTED_REQUEST_HEADERS = [
Expand Down
8 changes: 2 additions & 6 deletions mediaflow_proxy/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ async def handle_hls_stream_proxy(request: Request, destination: str, headers: d
if "mpegurl" in response.headers.get("content-type", "").lower():
return await fetch_and_process_m3u8(streamer, destination, headers, request, key_url)

headers.update({"accept-ranges": headers.get("range", "bytes=0-")})
headers.update({"range": headers.get("range", "bytes=0-")})
# clean up the headers to only include the necessary headers and remove acl headers
response_headers = {
k.title(): v for k, v in response.headers.items() if k.lower() in SUPPORTED_RESPONSE_HEADERS
}
# set chunked transfer encoding for streaming
response_headers["Transfer-Encoding"] = "chunked"

return StreamingResponse(
streamer.stream_content(destination, headers),
status_code=response.status_code,
status_code=206,
headers=response_headers,
background=BackgroundTask(streamer.close),
)
Expand Down Expand Up @@ -120,8 +118,6 @@ async def handle_stream_request(method: str, video_url: str, headers: dict):
await streamer.close()
return Response(headers=response_headers, status_code=response.status_code)
else:
# set chunked transfer encoding for streaming
response_headers["Transfer-Encoding"] = "chunked"
return StreamingResponse(
streamer.stream_content(video_url, headers),
headers=response_headers,
Expand Down

0 comments on commit 8013acb

Please sign in to comment.