Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed proxying with Range header #607

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions custom_components/yandex_station/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,23 @@ async def head(self, request: web.Request, sid: str, uid: str, ext: str):
if not url or hashlib.md5(url.encode()).hexdigest() != uid:
return web.HTTPNotFound()

async with self.session.head(url) as r:
return web.Response(
headers={
rng = request.headers.get("Range")
headers = {"Range": rng} if rng else None
async with self.session.head(url, headers=headers) as r:
response = web.Response(status=r.status)
response.headers.update(r.headers)

# important for DLNA players
response.headers.update({
"Content-Type": MIME_TYPES[ext],
})

if not rng:
response.headers.update({
"Accept-Ranges": "bytes",
# important for DLNA players
"Content-Type": MIME_TYPES[ext],
# inportant for SamsungTV
"Content-Length": r.headers["Content-Length"],
}
)
})

return response

async def get(self, request: web.Request, sid: str, uid: str, ext: str):
url: str = self.links.get(sid)
Expand All @@ -479,8 +486,19 @@ async def get(self, request: web.Request, sid: str, uid: str, ext: str):
rng = request.headers.get("Range")
headers = {"Range": rng} if rng else None
async with self.session.get(url, headers=headers) as r:
response = web.StreamResponse()
response = web.StreamResponse(status=r.status)
response.headers.update(r.headers)

# important for DLNA players
response.headers.update({
"Content-Type": MIME_TYPES[ext],
})

if not rng:
response.headers.update({
"Accept-Ranges": "bytes",
})

await response.prepare(request)

# same chunks as default web.FileResponse
Expand Down
Loading