Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for context manager responses #1341

Closed
wants to merge 3 commits into from

Conversation

florimondmanca
Copy link
Member

@florimondmanca florimondmanca commented Oct 3, 2020

Refs encode/httpcore#145, originally proof-of-concept'd via #1340

Prepare the migration of the transport API returning context manager responses, by adding support for either a response tuple (current behavior), or a context manager containing a response tuple.

Once this is in, we can go ahead and move forward on the HTTPCore side, e.g. with encode/httpcore#206, without risking breakage on the HTTPX side (since we'll support both versions of the transport API).

@florimondmanca florimondmanca added refactor Issues and PRs related to code refactoring httpcore Issues related to HTTPCore (core HTTP networking layer) - https://github.com/encode/httpcore labels Oct 3, 2020
@florimondmanca florimondmanca requested a review from a team October 3, 2020 11:11
@tomchristie
Copy link
Member

Okey dokes, so I've worked through a POC showing how we can deal with this, by changing the stack so that we're using context manager interfaces throughout... https://gist.github.com/tomchristie/e6e5e06b6c7b77b9c726b74d1ba0acbc

Some nice things drop out of this, because it's always clear if a response is still in an opened state or not, because you're always inside a with ... as response: block. And you don't ever need to wrap bits of code up in try ... except response.close(), which for example we were doing with event hooks.

@florimondmanca
Copy link
Member Author

Closing in favor of #1355 since that looks more promising than this PR. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
httpcore Issues related to HTTPCore (core HTTP networking layer) - https://github.com/encode/httpcore refactor Issues and PRs related to code refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants