Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async def getDataFromServerGen(connection):
- while True:
- try:
- chunk = await connection.content.read(2048) # can rise error if connection close!
- if not chunk: break
- yield chunk
- except:
- break
- async def ForwardUrlStream( url, request_headers ):
- del request_headers["host"]
- session = ClientSession(headers=request_headers)
- server_connection = await session.get(url)
- async def fwd(res):
- async with server_connection:
- async for chunk in getDataFromServerGen(server_connection):
- await res.write(chunk)
- await session.close()
- allowed_headers = ['Accept-Ranges', 'Content-Type', 'Content-Length', 'Content-Range', 'Accept-Encoding', 'Accept']
- response_headers = dict(filter(lambda elem: elem[0] in allowed_headers, server_connection.headers.items()))
- return response.stream(fwd, content_type="video/mp4", status=server_connection.status, headers=response_headers)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement