head request

This commit is contained in:
Roy Olav Purser 2021-04-30 17:51:09 +02:00
parent 6650cd1818
commit 7374cfed9d
No known key found for this signature in database
GPG Key ID: 0BA77797F072BC52

View File

@ -24,7 +24,7 @@ for key in proxies:
proxies[key].set_option("https-proxy", proxy) proxies[key].set_option("https-proxy", proxy)
class MainHandler(tornado.web.RequestHandler): class MainHandler(tornado.web.RequestHandler):
def get(self): def handle_any(self, write):
provider = self.get_query_argument("provider", None) provider = self.get_query_argument("provider", None)
endpoint = None endpoint = None
if provider is not None and provider in providers.keys(): if provider is not None and provider in providers.keys():
@ -35,7 +35,8 @@ class MainHandler(tornado.web.RequestHandler):
if resp is not None: if resp is not None:
src = resp.url src = resp.url
except Exception as e: except Exception as e:
self.write(e) if write:
self.write(e)
return return
else: else:
try: try:
@ -46,12 +47,18 @@ class MainHandler(tornado.web.RequestHandler):
endpoint = stream.url endpoint = stream.url
break break
except Exception as e: except Exception as e:
self.write(str(e)) if write:
self.write(str(e))
return return
if endpoint is None: if endpoint is None:
self.write("stream not found") if write:
self.write("stream not found")
else: else:
self.redirect(endpoint, status=303) self.redirect(endpoint, status=303)
def get(self):
self.handle_any(True)
def head(self):
self.handle_any(False)
try: try:
app_web = tornado.web.Application([(tornado.routing.AnyMatches(), MainHandler)]) app_web = tornado.web.Application([(tornado.routing.AnyMatches(), MainHandler)])
app_web.listen(8080) app_web.listen(8080)