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 response.next_request #1334

Merged
merged 3 commits into from
Oct 1, 2020
Merged

Add response.next_request #1334

merged 3 commits into from
Oct 1, 2020

Conversation

tomchristie
Copy link
Member

Currently when using allow_redirects=False, we have interfaces for response.next() and response.anext(),
which can be used to issue the next redirect request.

The intent of these is to mirror the interface from requests, which also has a response.next.

However It turns out that I've made an error in what I thought the interface we were mirroring does. When using requests with allow_redirects=False, the response.next isn't a callable. It's an optional request instance, that can be used with client.send(...) to send the next response.

Since one of our desired aims is for full parity with requests, we ought to be covering that API, and not the callable .next interface that we're currently exposing.

client = httpx.Client()
request = client.build_request("GET", ...)
while request is not None:
    response = client.send(request, allow_redirects=False)
    request = response.next_request

This pull request adds response.next_request as a more clearly named version of the requests API.

In the next version bump I think we should follow up on this PR by removing response.next() and response.anext() as unnecessary bits of API.

@tomchristie tomchristie added the requests-compat Issues related to Requests backwards compatibility label Oct 1, 2020
Copy link
Member

@jcugat jcugat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love how this feature it's just a couple lines of code, brilliant!

@tomchristie tomchristie merged commit 3f51392 into master Oct 1, 2020
@tomchristie tomchristie deleted the next-request branch October 1, 2020 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requests-compat Issues related to Requests backwards compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants