Resetting utils subtree.
This commit is contained in:
+24
-1
@@ -42,7 +42,7 @@ import os
|
||||
import psutil
|
||||
|
||||
# For using Quart:
|
||||
from quart import Quart, request, current_app
|
||||
from quart import Quart, request, current_app, redirect
|
||||
from quart_cors import cors
|
||||
|
||||
# Common:
|
||||
@@ -181,6 +181,29 @@ async def app_shutdown(**kwargs):
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@app.before_request
|
||||
async def enforce_https():
|
||||
|
||||
"""
|
||||
Here we enforce HTTPS (secure) requests and effectively reject unsecure requests. We make exemptions for local
|
||||
network requests for regular testing.
|
||||
:return: A redirect to the secure version if the incoming request is not secure.
|
||||
"""
|
||||
|
||||
# If the connection is not secure:
|
||||
if request.scheme != "https":
|
||||
|
||||
# Check if it is a local IP. If not, redirect:
|
||||
exempt_ips = ["0.0.0.0", "127.0.0.1"]
|
||||
if not (
|
||||
request.remote_addr.startswith("192.168.") or
|
||||
request.remote_addr in exempt_ips
|
||||
): return redirect(request.url.replace("http", "https"))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@app.route(f"/", methods = ["GET", "POST"])
|
||||
@app.route(f"/{MODULE_BASE}", methods = ["GET", "POST"])
|
||||
async def root():
|
||||
|
||||
Reference in New Issue
Block a user