From 67721e87cd291feefbfe26ba422891c30e045e79 Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Sun, 25 Feb 2024 20:05:13 +0530 Subject: [PATCH] added async httpx library for request processing add sample request processing for app call messages --- .../Testing/Veilid/Alice-Python-Server.ipynb | 2 +- packages/grid/veilid/requirements.txt | 1 + packages/grid/veilid/server/veilid_core.py | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/notebooks/Testing/Veilid/Alice-Python-Server.ipynb b/notebooks/Testing/Veilid/Alice-Python-Server.ipynb index 332517869d0..b398119c7f0 100644 --- a/notebooks/Testing/Veilid/Alice-Python-Server.ipynb +++ b/notebooks/Testing/Veilid/Alice-Python-Server.ipynb @@ -185,7 +185,7 @@ "source": [ "res = requests.get(\n", " f\"http://{host}:{port}/proxy\",\n", - " json={\"url\": \"https://www.google.com\", \"dht_key\": self_dht_key},\n", + " json={\"url\": \"https://www.google.com\", \"method\": \"GET\", \"dht_key\": self_dht_key},\n", ")" ] }, diff --git a/packages/grid/veilid/requirements.txt b/packages/grid/veilid/requirements.txt index 20539a66cda..4d83d470465 100644 --- a/packages/grid/veilid/requirements.txt +++ b/packages/grid/veilid/requirements.txt @@ -1,3 +1,4 @@ fastapi==0.103.2 +httpx==0.27.0 loguru==0.7.2 uvicorn[standard]==0.24.0.post1 diff --git a/packages/grid/veilid/server/veilid_core.py b/packages/grid/veilid/server/veilid_core.py index 166a5e8956c..3feb2deba42 100644 --- a/packages/grid/veilid/server/veilid_core.py +++ b/packages/grid/veilid/server/veilid_core.py @@ -1,10 +1,12 @@ # stdlib +import json from typing import Callable from typing import Optional from typing import Tuple from typing import Union # third party +import httpx from loguru import logger import veilid from veilid import KeyPair @@ -33,8 +35,19 @@ async def main_callback(update: VeilidUpdate) -> None: elif update.kind == veilid.VeilidUpdateKind.APP_CALL: logger.info(f"Received App Call: {update.detail.message}") + message: dict = json.loads(update.detail.message) + + async with httpx.AsyncClient() as client: + response = await client.request( + method=message.get("method"), + url=message.get("url"), + data=message.get("data", None), + params=message.get("params", None), + json=message.get("json", None), + ) + async with await get_veilid_conn() as conn: - await conn.app_call_reply(update.detail.call_id, b"Reply from App Call") + await conn.app_call_reply(update.detail.call_id, response.content) async def noop_callback(update: VeilidUpdate) -> None: