2021-08-25 01:33:29 +00:00
|
|
|
import logging
|
|
|
|
import requests
|
|
|
|
|
|
|
|
from app.classes.shared.helpers import helper
|
|
|
|
from app.classes.web.base_handler import BaseHandler
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2022-03-23 02:50:12 +00:00
|
|
|
|
|
|
|
|
2021-08-25 01:33:29 +00:00
|
|
|
class HTTPHandlerPage(BaseHandler):
|
2022-01-26 01:45:30 +00:00
|
|
|
def get(self):
|
2021-08-25 01:33:29 +00:00
|
|
|
url = self.request.full_url
|
|
|
|
port = 443
|
2022-03-23 02:50:12 +00:00
|
|
|
if url[len(url) - 1] == "/":
|
|
|
|
url = url.strip(url[len(url) - 1])
|
|
|
|
url_list = url.split("/")
|
2021-08-25 01:33:29 +00:00
|
|
|
if url_list[0] != "":
|
2022-03-23 02:50:12 +00:00
|
|
|
primary_url = url_list[0] + ":" + str(port) + "/"
|
|
|
|
backup_url = url_list[0] + ":" + str(helper.get_setting("https_port")) + "/"
|
|
|
|
for i in range(len(url_list) - 1):
|
|
|
|
primary_url += url_list[i + 1]
|
|
|
|
backup_url += url_list[i + 1]
|
2021-08-25 01:33:29 +00:00
|
|
|
else:
|
|
|
|
primary_url = url + str(port)
|
2022-03-23 02:50:12 +00:00
|
|
|
backup_url = url + str(helper.get_setting("https_port"))
|
2022-01-26 01:45:30 +00:00
|
|
|
|
2021-08-25 01:33:29 +00:00
|
|
|
try:
|
|
|
|
resp = requests.get(primary_url)
|
|
|
|
resp.raise_for_status()
|
|
|
|
url = primary_url
|
2022-01-26 01:45:30 +00:00
|
|
|
except Exception:
|
2021-08-25 01:33:29 +00:00
|
|
|
url = backup_url
|
2022-03-23 02:50:12 +00:00
|
|
|
self.redirect("https://" + url + ":" + str(port))
|