def force_https(request):
host = request.headers.get('Host', '')
# get scheme, first by checking the x-forwarded-proto (from nginx/heroku etc)
# then falling back on whether or not there is an sslcontext
scheme = request.headers.get(
'x-forwarded-proto',
"https" if request.transport.get_extra_info('sslcontext') else "http")
if not host.startswith("localhost:") and scheme != "https":
url = urlunparse((
"https",
host,
request.path,
None,
request.query_string,
None))
return redirect(url)
评论列表
文章目录