This repository was archived by the owner on Apr 14, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 22
Send request through trio backend #3
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3195a5
Fix flake8 errors
pquentin 8f196cb
Send request and receive headers with trio backend
pquentin 5b55aef
Fix async read() in trio backend
pquentin b5566f3
Fix accidentally quadratic behavior
pquentin 49a15ee
Move _start_http_response out of class
pquentin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import trio | ||
import urllib3 | ||
from urllib3.backends.trio_backend import TrioBackend | ||
|
||
|
||
async def main(): | ||
http = urllib3.PoolManager(TrioBackend()) | ||
r = await http.request('GET', 'http://httpbin.org/robots.txt', preload_content=False) | ||
print(r.status) # prints "200" | ||
print(await r.read()) # prints "User-agent: *\nDisallow: /deny\n" | ||
|
||
trio.run(main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, forceful close raises such tricky questions for API design.
I started to write a long thing here about why
close
should maybe be synchronous after all. Trio's abstract stream interface makes it async because it's, y'know, abstract, and some streams need it to be async. But for the particular concrete streams that urllib3 uses, it's always synchronous. So maybe, I was thinking, it should be synchronous here too, and we'd make the trio backend jump through the necessary hoops to make that work.Then l looked at twisted and asyncio and realized that they also make closing a socket an async operation for weird API reasons, so fine, let's just make it async :-). It's an issue we might want to revisit in the future though as this develops. (I'm also inclined to say that if we're going to make closing async, we should rename it
aclose
, which is the convention that trio uses; I stole it from the interpreter's async generator API. But that's also something we can worry about later.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. So
forceful_close
should becomeaclose_forcefully
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I guess it could. That doesn't matter too much though, because the backend API is internal anyway. The more important question is whether we want to rename
Response.close
,PoolManager.close
, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll prepare another PR for this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just opened #4.