new test
This commit is contained in:
parent
38351f27e0
commit
b67b8558d0
16
stream.py
16
stream.py
@ -48,6 +48,9 @@ class ProxyElem():
|
||||
return resp.headers.get("Content-Type", "binary/octet-stream")
|
||||
async def proxy_url(self, current, path):
|
||||
data = {}
|
||||
if path is None:
|
||||
data["upstream"] = current
|
||||
else:
|
||||
data["upstream"] = urllib.parse.urljoin(current, path)
|
||||
data["proxied"] = True
|
||||
ret = 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,6 +334,10 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
if data is None:
|
||||
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")
|
||||
|
Loading…
Reference in New Issue
Block a user