Skip to content

Commit

Permalink
Merge pull request #607 from Laxilef/patch-2
Browse files Browse the repository at this point in the history
Fixed proxying with ``Range`` header
  • Loading branch information
AlexxIT authored Jan 17, 2025
2 parents 4e3320c + 9cadfa9 commit 7fcc2a4
Showing 1 changed file with 28 additions and 10 deletions.
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 @@ -470,16 +470,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 @@ -490,8 +497,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

0 comments on commit 7fcc2a4

Please # to comment.