Spaces:
Running
Running
Fix streaming header & status issue
Browse files- mediaflow_proxy/const.py +0 -6
- mediaflow_proxy/handlers.py +2 -6
mediaflow_proxy/const.py
CHANGED
@@ -9,12 +9,6 @@ SUPPORTED_RESPONSE_HEADERS = [
|
|
9 |
"etag",
|
10 |
"server",
|
11 |
"date",
|
12 |
-
"cache-control",
|
13 |
-
"expires",
|
14 |
-
"pragma",
|
15 |
-
"content-disposition",
|
16 |
-
"range",
|
17 |
-
"content-encoding",
|
18 |
]
|
19 |
|
20 |
SUPPORTED_REQUEST_HEADERS = [
|
|
|
9 |
"etag",
|
10 |
"server",
|
11 |
"date",
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
]
|
13 |
|
14 |
SUPPORTED_REQUEST_HEADERS = [
|
mediaflow_proxy/handlers.py
CHANGED
@@ -47,17 +47,15 @@ async def handle_hls_stream_proxy(request: Request, destination: str, headers: d
|
|
47 |
if "mpegurl" in response.headers.get("content-type", "").lower():
|
48 |
return await fetch_and_process_m3u8(streamer, destination, headers, request, key_url)
|
49 |
|
50 |
-
headers.update({"
|
51 |
# clean up the headers to only include the necessary headers and remove acl headers
|
52 |
response_headers = {
|
53 |
k.title(): v for k, v in response.headers.items() if k.lower() in SUPPORTED_RESPONSE_HEADERS
|
54 |
}
|
55 |
-
# set chunked transfer encoding for streaming
|
56 |
-
response_headers["Transfer-Encoding"] = "chunked"
|
57 |
|
58 |
return StreamingResponse(
|
59 |
streamer.stream_content(destination, headers),
|
60 |
-
status_code=
|
61 |
headers=response_headers,
|
62 |
background=BackgroundTask(streamer.close),
|
63 |
)
|
@@ -120,8 +118,6 @@ async def handle_stream_request(method: str, video_url: str, headers: dict):
|
|
120 |
await streamer.close()
|
121 |
return Response(headers=response_headers, status_code=response.status_code)
|
122 |
else:
|
123 |
-
# set chunked transfer encoding for streaming
|
124 |
-
response_headers["Transfer-Encoding"] = "chunked"
|
125 |
return StreamingResponse(
|
126 |
streamer.stream_content(video_url, headers),
|
127 |
headers=response_headers,
|
|
|
47 |
if "mpegurl" in response.headers.get("content-type", "").lower():
|
48 |
return await fetch_and_process_m3u8(streamer, destination, headers, request, key_url)
|
49 |
|
50 |
+
headers.update({"range": headers.get("range", "bytes=0-")})
|
51 |
# clean up the headers to only include the necessary headers and remove acl headers
|
52 |
response_headers = {
|
53 |
k.title(): v for k, v in response.headers.items() if k.lower() in SUPPORTED_RESPONSE_HEADERS
|
54 |
}
|
|
|
|
|
55 |
|
56 |
return StreamingResponse(
|
57 |
streamer.stream_content(destination, headers),
|
58 |
+
status_code=206,
|
59 |
headers=response_headers,
|
60 |
background=BackgroundTask(streamer.close),
|
61 |
)
|
|
|
118 |
await streamer.close()
|
119 |
return Response(headers=response_headers, status_code=response.status_code)
|
120 |
else:
|
|
|
|
|
121 |
return StreamingResponse(
|
122 |
streamer.stream_content(video_url, headers),
|
123 |
headers=response_headers,
|