Fix issue where Force HTTPS was ignored

This commit is contained in:
Taylor Helsper 2021-07-04 22:05:37 -05:00
parent a5bc98c510
commit 347fb1b607

View File

@ -677,9 +677,11 @@ def internal_error(error):
# Check for forced HTTPS # Check for forced HTTPS
@app.before_request @app.before_request
def before_request(): def before_request():
if is_https_forced(): # Check for HTTPS forced (only enforce once drive mounted and stable state)
scheme = request.headers.get('X-Forwarded-Proto') # Otherwise, web GUI may be inaccessible if error occurs (NGINX needs drive for cert)
if scheme and scheme == 'http' and request.url.startswith('http://'): if is_https_forced() and get_mynode_status() == STATE_STABLE:
if request.url and request.url.startswith('http://'):
app.logger.info("REDIRECTING")
url = request.url.replace('http://', 'https://', 1) url = request.url.replace('http://', 'https://', 1)
code = 302 code = 302
app.logger.info("Redirecting to HTTPS ({})".format(url)) app.logger.info("Redirecting to HTTPS ({})".format(url))