new test
This commit is contained in:
parent
38351f27e0
commit
b67b8558d0
20
stream.py
20
stream.py
@ -48,7 +48,10 @@ class ProxyElem():
|
||||
return resp.headers.get("Content-Type", "binary/octet-stream")
|
||||
async def proxy_url(self, current, path):
|
||||
data = {}
|
||||
data["upstream"] = urllib.parse.urljoin(current, path)
|
||||
if path is None:
|
||||
data["upstream"] = current
|
||||
else:
|
||||
data["upstream"] = urllib.parse.urljoin(current, path)
|
||||
data["proxied"] = True
|
||||
ret = None
|
||||
if self.proxy is None:
|
||||
@ -58,9 +61,14 @@ class ProxyElem():
|
||||
if proxy_server is None:
|
||||
return data["upstream"]
|
||||
async with self.session() as session:
|
||||
resp = await session.post(proxy_server, json=data)
|
||||
resp = await session.post(proxy_server, json=[data])
|
||||
text = await resp.text()
|
||||
return json.loads(text)
|
||||
jdata = json.loads(text)
|
||||
logger.info(jdata)
|
||||
if isinstance(jdata, list) and len(jdata) == 1:
|
||||
return jdata[0]
|
||||
else:
|
||||
return data["upstream"]
|
||||
|
||||
class AsyncSession():
|
||||
def __init__(self, session, future):
|
||||
@ -326,7 +334,11 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
if data is None:
|
||||
self.redirect(upstream, status=303)
|
||||
links = await handler.proxy.proxy_url(upstream, None)
|
||||
if isinstance(links, list) and len(links) == 1:
|
||||
self.redirect(links[0], status=303)
|
||||
else:
|
||||
self.redirect(upstream, status=303)
|
||||
else:
|
||||
self.set_header("Content-Type", "application/vnd.apple.mpegurl")
|
||||
self.write(data)
|
||||
|
Loading…
Reference in New Issue
Block a user