retry content type
This commit is contained in:
parent
97563dec60
commit
df153d5a12
21
stream.py
21
stream.py
@ -48,14 +48,18 @@ class ProxyElem():
|
||||
def __repr__(self):
|
||||
return str(self.proxy)
|
||||
async def content_type(self, url):
|
||||
ctype = "binary/octet-stream"
|
||||
try:
|
||||
async with self.session() as session:
|
||||
resp = await session.head(url)
|
||||
ctype = resp.headers.get("Content-Type", "binary/octet-stream")
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
return ctype
|
||||
ctype = None
|
||||
async with self.session() as session:
|
||||
for i in range(5):
|
||||
try:
|
||||
resp = await session.head(url)
|
||||
ctype = resp.headers.get("Content-Type", None)
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
else:
|
||||
if isinstance(ctype, str):
|
||||
return ctype
|
||||
return "binary/octet-type"
|
||||
async def proxy_url(self, current, path):
|
||||
jdata = None
|
||||
data = {}
|
||||
@ -348,7 +352,6 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
else:
|
||||
upstream_proxy = await handler.proxy.proxy_url(upstream, None)
|
||||
ctype = await handler.proxy.content_type(upstream_proxy)
|
||||
logger.info(upstream_proxy)
|
||||
data = None
|
||||
if "mpegurl" in ctype.lower():
|
||||
data = await rewrite(upstream, handler.proxy)
|
||||
|
Loading…
Reference in New Issue
Block a user