Skip to content

Commit

Permalink
Fix the aiohttp examples to clean up resources
Browse files Browse the repository at this point in the history
The previously present snippets presented a misuse of `aiohttp`'s APIs. While technically they work, they don't release the allocated resources like async CMs would. And so we recommend using the latter.
  • Loading branch information
webknjaz authored and sethmlarson committed May 30, 2024
1 parent 489074a commit 5dccaad
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ import truststore
truststore.inject_into_ssl()
http = aiohttp.ClientSession()
resp = await http.request("GET", "https://example.com")
async with aiohttp.ClientSession() as http_client:
async with http_client.get("https://example.com") as http_response:
...
```

If you'd like to use the `truststore.SSLContext` directly you can pass
Expand All @@ -154,8 +155,9 @@ import truststore
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
http = aiohttp.ClientSession(ssl=ctx)
resp = await http.request("GET", "https://example.com")
async with aiohttp.ClientSession(ssl=ctx) as http_client:
async with http_client.get("https://example.com") as http_response:
...
```

### Using truststore with Requests
Expand Down

0 comments on commit 5dccaad

Please sign in to comment.