Created
January 16, 2024 20:31
-
-
Save drizzt/93d253bca4f64fae7df2a4544a98c08d to your computer and use it in GitHub Desktop.
PUT to POST proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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