Skip to content

Add response.next_request - #1334

Merged
lovelydinosaur merged 3 commits into
masterfrom
next-request
Oct 1, 2020
Merged

Add response.next_request#1334
lovelydinosaur merged 3 commits into
masterfrom
next-request

Conversation

@lovelydinosaur

Copy link
Copy Markdown
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.nextisn'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", ...)
whilerequestisnotNone:
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.

@lovelydinosaurlovelydinosaur added the requests-compat Issues related to Requests backwards compatibility label Oct 1, 2020

@jcugatjcugat left a comment

Copy link
Copy Markdown
Contributor

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!

@lovelydinosaur
lovelydinosaur merged commit 3f51392 into masterOct 1, 2020
@lovelydinosaur
lovelydinosaur deleted the next-request branch October 1, 2020 12:52
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requests-compatIssues related to Requests backwards compatibility

Development

Successfully merging this pull request may close these issues.

2 participants

@lovelydinosaur@jcugat