From 0c7119dbebcb588335f3753b4c0f04b3c49f8100 Mon Sep 17 00:00:00 2001 From: agatha Date: Wed, 11 Oct 2023 17:35:54 -0400 Subject: [PATCH] Add basic HTTP/2 example --- src/examples/httpx-example.py | 26 ++++++++++++++++++++++++++ src/requirements.txt | 5 +++-- src/rr.py | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/examples/httpx-example.py create mode 100644 src/rr.py diff --git a/src/examples/httpx-example.py b/src/examples/httpx-example.py new file mode 100644 index 0000000..3cd20f7 --- /dev/null +++ b/src/examples/httpx-example.py @@ -0,0 +1,26 @@ +import asyncio +import httpx + + +async def make_http2_request(url): + try: + async with httpx.AsyncClient(http2=True, verify=False) as client: + response = await client.get(url) + return response + except httpx.RequestError as e: + print(f'[!] error occurred while making the request: {e}') + return None + + +def main(): + url = 'https://localhost/' + + response = asyncio.run(make_http2_request(url)) + + print('Response object type:', type(response)) + print('Response HTTP version:', response.http_version) + print('Response headers:', response.headers) + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/src/requirements.txt b/src/requirements.txt index 8d24666..549556e 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,2 +1,3 @@ -httpx -h2 \ No newline at end of file +asyncio +h2 +httpx[http2] diff --git a/src/rr.py b/src/rr.py new file mode 100644 index 0000000..5cd6828 --- /dev/null +++ b/src/rr.py @@ -0,0 +1 @@ +"""rrpoc"""