Advertisement
Guest User

feature_flags.py

a guest
Nov 14th, 2024
2
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. from fastapi import Request
  2. import httpx
  3. from app.config import settings
  4.  
  5. async def mirror_request(request: Request, body: dict = None):
  6.     if not settings.ENABLE_SHADOW_REQUESTS or not settings.SHADOW_API_URL:
  7.         return
  8.  
  9.     async with httpx.AsyncClient() as client:
  10.         try:
  11.             await client.request(
  12.                 method=request.method,
  13.                 url=f"{settings.SHADOW_API_URL}{request.url.path}",
  14.                 json=body,
  15.                 headers=request.headers
  16.             )
  17.         except Exception:
  18.             # Log error but don't affect main request
  19.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement