Skip to content

Commit

Permalink
added custom proxy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
rasswanth-s committed Feb 25, 2024
1 parent 139bcdf commit 871db0f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
33 changes: 32 additions & 1 deletion notebooks/Testing/Veilid/Alice-Python-Server.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,41 @@
"app_message = requests.post(f\"http://{host}:{port}/app_message\", json=json_data)"
]
},
{
"cell_type": "markdown",
"id": "153377f6-698e-4013-9be3-0833b71ee0c4",
"metadata": {},
"source": [
"### Send Proxy Message "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "271d7316-eaab-438c-9192-55a4e44b9dea",
"metadata": {},
"outputs": [],
"source": [
"res = requests.get(\n",
" f\"http://{host}:{port}/proxy\",\n",
" json={\"url\": \"https://www.google.com\", \"dht_key\": self_dht_key},\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "77e1ad1d-379a-4899-8805-c703ad437c0d",
"metadata": {},
"outputs": [],
"source": [
"res.content"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "169019a3-ced3-4bb2-b812-125f759af9ed",
"id": "73c1f0b0-d240-4964-a88b-365ea89b1bdd",
"metadata": {},
"outputs": [],
"source": []
Expand Down
14 changes: 14 additions & 0 deletions packages/grid/veilid/server/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# stdlib
import json
import os
import sys

Expand Down Expand Up @@ -65,6 +66,19 @@ async def app_call_endpoint(
return await app_call(dht_key=dht_key, message=message)


@app.api_route("/proxy", methods=["GET", "POST", "PUT"])
async def proxy(request: Request) -> dict[str, str]:
logger.info("Proxying request")
request_data = await request.json()
logger.info(f"Request URL: {request_data}")
dht_key = request_data.get("dht_key")
request_data.pop("dht_key")
logger.info(f"Request URL: {request_data}")
message = json.dumps(request_data).encode()
logger.info(f"Final Message: {message!r}")
return await app_call(dht_key=dht_key, message=message)


@app.on_event("startup")
async def startup_event() -> None:
try:
Expand Down

0 comments on commit 871db0f

Please sign in to comment.