def stuff_before_request():
g.request_start_time = time()
g.hybrid = False
if 'hybrid' in request.args.keys():
g.hybrid = True
logger.info(u"GOT HYBRID PARAM so will run with hybrid.")
# don't redirect http api in some cases
if request.url.startswith("http://api."):
return
if "staging" in request.url or "localhost" in request.url:
return
# redirect everything else to https.
new_url = None
try:
if request.headers["X-Forwarded-Proto"] == "https":
pass
elif "http://" in request.url:
new_url = request.url.replace("http://", "https://")
except KeyError:
# logger.info(u"There's no X-Forwarded-Proto header; assuming localhost, serving http.")
pass
# redirect to naked domain from www
if request.url.startswith("https://www.oadoi.org"):
new_url = request.url.replace(
"https://www.oadoi.org",
"https://oadoi.org"
)
logger.info(u"URL starts with www; redirecting to " + new_url)
if new_url:
return redirect(new_url, 301) # permanent
# convenience function because we do this in multiple places
评论列表
文章目录