Adilmar commited on
Commit
c8ecf05
·
verified ·
1 Parent(s): 7dfa26f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -9,23 +9,24 @@ AUTH_HEADER = os.environ.get("AUTH_HEADER")
9
 
10
  @app.api_route("/{full_path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"])
11
  async def proxy(full_path: str, request: Request):
12
- # Monta URL destino
13
  url = f"{BACKEND_URL}/{full_path}"
14
 
15
  # Copia headers originais e adiciona Authorization
16
  headers = dict(request.headers)
17
  headers["Authorization"] = AUTH_HEADER
18
 
19
- # corpo da requisição
 
 
 
20
  body = await request.body()
21
 
22
- # Faz requisição ao backend
23
  async with httpx.AsyncClient() as client:
24
  resp = await client.request(
25
  method=request.method,
26
  url=url,
27
  headers=headers,
28
- content=body,
29
  params=dict(request.query_params)
30
  )
31
 
@@ -33,7 +34,7 @@ async def proxy(full_path: str, request: Request):
33
  return Response(
34
  content=resp.content,
35
  status_code=resp.status_code,
36
- headers=dict(resp.headers)
37
  )
38
 
39
  # Para rodar:
 
9
 
10
  @app.api_route("/{full_path:path}", methods=["GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS"])
11
  async def proxy(full_path: str, request: Request):
 
12
  url = f"{BACKEND_URL}/{full_path}"
13
 
14
  # Copia headers originais e adiciona Authorization
15
  headers = dict(request.headers)
16
  headers["Authorization"] = AUTH_HEADER
17
 
18
+ # Remove headers que podem causar conflito
19
+ for h in ["host", "content-length", "accept-encoding", "connection"]:
20
+ headers.pop(h, None)
21
+
22
  body = await request.body()
23
 
 
24
  async with httpx.AsyncClient() as client:
25
  resp = await client.request(
26
  method=request.method,
27
  url=url,
28
  headers=headers,
29
+ content=body if request.method != "GET" else None,
30
  params=dict(request.query_params)
31
  )
32
 
 
34
  return Response(
35
  content=resp.content,
36
  status_code=resp.status_code,
37
+ headers={k: v for k, v in resp.headers.items() if k.lower() not in ["content-encoding", "transfer-encoding", "connection"]}
38
  )
39
 
40
  # Para rodar: