Silicon Valley - Admin commited on
Commit
ed02a4f
1 Parent(s): 42efabf

Refactor server.py to replace ProxyFix with ProxyHeadersMiddleware for improved proxy handling

Browse files

- Updated server.py to import ProxyHeadersMiddleware from Starlette and applied it to manage proxy headers.
- Adjusted middleware configuration for better clarity and maintainability, ensuring compatibility with ASGI applications.

Files changed (1) hide show
  1. server.py +9 -6
server.py CHANGED
@@ -11,7 +11,7 @@ from typing import Any, AsyncGenerator, Dict, Tuple, Union
11
 
12
  from quart import Quart, websocket, request, send_from_directory
13
  from quart_schema import QuartSchema, validate_request, validate_response
14
- from werkzeug.middleware.proxy_fix import ProxyFix # Importar ProxyFix de werkzeug
15
 
16
  # Configuraciones
17
  TIMEOUT: int = 40
@@ -21,11 +21,14 @@ TRUSTED_HOSTS: list[str] = ["127.0.0.1", "172.18.0.3"]
21
  # Inicializaci贸n de la aplicaci贸n Quart
22
  app = Quart(__name__)
23
  QuartSchema(app)
24
-
25
- # Aplicar ProxyFix para manejar encabezados de proxy
26
- # Ajusta los par谩metros seg煤n la cantidad de proxies delante de tu aplicaci贸n
27
- app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1, x_port=1, x_prefix=1)
28
-
 
 
 
29
  app.logger.setLevel(LOG_LEVEL)
30
 
31
  # Excepciones personalizadas
 
11
 
12
  from quart import Quart, websocket, request, send_from_directory
13
  from quart_schema import QuartSchema, validate_request, validate_response
14
+ from starlette.middleware.proxy_headers import ProxyHeadersMiddleware # Importar ProxyHeadersMiddleware de Starlette
15
 
16
  # Configuraciones
17
  TIMEOUT: int = 40
 
21
  # Inicializaci贸n de la aplicaci贸n Quart
22
  app = Quart(__name__)
23
  QuartSchema(app)
24
+ app.asgi_app = ProxyHeadersMiddleware(
25
+ app.asgi_app,
26
+ x_for=1,
27
+ x_proto=1,
28
+ x_host=1,
29
+ x_port=1,
30
+ x_prefix=1
31
+ )
32
  app.logger.setLevel(LOG_LEVEL)
33
 
34
  # Excepciones personalizadas