Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
fastapi/uvicorn evita descomprimir con httpx.AsyncClinet

trabajo en proxy inverso basado en fastapi. Quiero enviar de forma transparente los datos solicitados por AsyncClient. Tengo un problema con las páginas comprimidas con gzip. Por favor, ¿pueden ayudarme, cómo evitar la descompresión predeterminada de resp.content en este ejemplo?

 @app.get("/{path:path}") async def _get ( path: str, request: Request ): url = await my_proxy_logic (path, request) async with httpx.AsyncClient() as client: req = client.build_request("GET", url) resp = await client.send(req, stream=False) return Response( status_code=resp.status_code, headers=resp.headers, content=resp.content)```
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Es posible extraer datos no decodificados de la respuesta de httpx solo en el caso del modo de transmisión stream=True o httpx.stream . En el siguiente ejemplo, recopilo la respuesta completa usando aiter_raw y la devuelvo desde la operación de ruta. Tenga en cuenta que toda la respuesta se carga en la memoria, si desea evitar esto, use fastapi StreamingResponse

 import httpx from fastapi import FastAPI, Request, Response app = FastAPI() @app.get("/pass") async def root(request: Request): async with httpx.AsyncClient() as client: req = client.build_request('GET', 'http://httpbin.org/gzip') resp = await client.send(req, stream=True) return Response(status_code=resp.status_code, headers=resp.headers, content=b"".join([part async for part in resp.aiter_raw()]))
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!