Skip to content

Instantly share code, notes, and snippets.

@drizzt
Created January 16, 2024 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drizzt/93d253bca4f64fae7df2a4544a98c08d to your computer and use it in GitHub Desktop.
Save drizzt/93d253bca4f64fae7df2a4544a98c08d to your computer and use it in GitHub Desktop.
PUT to POST proxy
#!/usr/bin/python3
import uvloop
uvloop.install()
from starlette.applications import Starlette
from starlette.responses import Response
from starlette.routing import Route
import httpx
async def topic(request):
path = request.path_params["path"]
body = await request.body()
# Forward the request to the target URL
async with httpx.AsyncClient() as client:
upstream_response = await client.post(
url=path,
data=body,
)
return Response(
content=upstream_response.content, status_code=upstream_response.status_code
)
app = Starlette(
routes=[
Route("/{path:path}", topic, methods=["PUT"]),
],
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment