no redirect on head

This commit is contained in:
Roy Olav Purser 2021-05-14 15:43:24 +02:00
parent f2c5384699
commit acb04a3f54
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -260,13 +260,13 @@ def rewrite(current, provider, proxy):
ndata += "\n"
return ndata
class MainHandler(tornado.web.RequestHandler):
async def handle_any(self):
async def handle_any(self, redir):
handler = UpstreamHandler()
await handler.setup(self)
if handler.render:
await self.handle_render(handler)
elif handler.stream:
await self.handle_stream(handler)
await self.handle_stream(handler, redir)
else:
logger.info(f'provider missing {self.request.uri}')
self.set_status(404)
@ -290,7 +290,7 @@ class MainHandler(tornado.web.RequestHandler):
self.set_status(404)
self.write("HTML template missing.")
async def handle_stream(self, handler):
async def handle_stream(self, handler, redir):
upstream = None
if handler.proxy is not None:
try:
@ -319,6 +319,9 @@ class MainHandler(tornado.web.RequestHandler):
data = None
if "mpegurl" in ctype.lower():
data = rewrite(upstream, provider, proxy)
self.set_header("Content-Type", "application/vnd.apple.mpegurl")
else:
self.set_header("Content-Type", ctype)
else:
ldata = {}
ldata["upstream"] = upstream
@ -335,15 +338,15 @@ class MainHandler(tornado.web.RequestHandler):
except Exception as e:
logger.info(e)
if data is None:
if redir:
upstream = await handler.proxy.proxy_url(upstream, None)
self.redirect(upstream, status=303)
else:
self.set_header("Content-Type", "application/vnd.apple.mpegurl")
self.write(data)
async def get(self):
await self.handle_any()
await self.handle_any(True)
async def head(self):
await self.handle_any()
await self.handle_any(False)
class FileHandler(tornado.web.RequestHandler):
def get(self):