Skip to content

Instantly share code, notes, and snippets.

@drizzt
Created January 16, 2024 20:31
Show Gist options
  • Select an option

  • Save drizzt/93d253bca4f64fae7df2a4544a98c08d to your computer and use it in GitHub Desktop.

Select an option

Save drizzt/93d253bca4f64fae7df2a4544a98c08d to your computer and use it in GitHub Desktop.

Revisions

  1. drizzt revised this gist Jan 16, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion main.py
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,6 @@ async def topic(request):


    app = Starlette(
    debug=True,
    routes=[
    Route("/{path:path}", topic, methods=["PUT"]),
    ],
  2. drizzt created this gist Jan 16, 2024.
    37 changes: 37 additions & 0 deletions main.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    #!/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(
    debug=True,
    routes=[
    Route("/{path:path}", topic, methods=["PUT"]),
    ],
    )