Skip to content

Save history if authentication flow makes more than one request - #686

Closed
gdhameeja wants to merge 2 commits into
encode:masterfrom
gdhameeja:Fix-669
Closed

gdhameeja wants to merge 2 commits into
encode:masterfrom
gdhameeja:Fix-669

Conversation

@gdhameeja

Copy link
Copy Markdown
Contributor

Fixes #669
Saves the response to history if authentication flow makes more than one request. This history is assigned to response.history

@gdhameeja

Copy link
Copy Markdown
Contributor Author

There is an ugly counter variable that we use to keep track of the number of requests made in send_handling_auth. Maybe this can be done in a better way, that I could not think of currently. Please suggest.

@florimondmanca florimondmanca 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.

Thanks! Left a refactoring suggestion.

Comment thread httpx/client.py Outdated

@florimondmanca florimondmanca 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.

Great, thanks! Just a final nit.

Comment thread httpx/client.py
@gdhameeja

Copy link
Copy Markdown
Contributor Author

Great, thanks! Just a final nit.

Fixed.

@florimondmanca florimondmanca 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.

Thanks!

Sorry for the dribs-and-drabs review, but I just realised this would ideally need some testing. Can we add one, ideally separate from the DigestAuth tests? (e.g. create an adhoc Auth subclass that e.g. sends the request twice, and verify the intermediate response is in the history)

@j178

j178 commented Jan 2, 2020 •

Copy link
Copy Markdown
Contributor

From code in these lines: https://github.com/encode/httpx/blob/master/httpx/client.py#L456-L463, I think the history desigin is that every response in the history also got a history at its own perspective, but those responses created during handling auth don't have its own history, I think this is a little inconsistent.

@gdhameeja

Copy link
Copy Markdown
Contributor Author

@florimondmanca I added a test. Can you please review this?
Thanks.

@florimondmanca

Copy link
Copy Markdown
Contributor

@gdhameeja Thanks! After thinking quite deeply about it, I agree with @j178 that there's a slight inconsistency compared to redirects in that the response.history for intermediate responses isn't populated.

Since I ended up with a complete implementation and tests, and before I saw your last comment :-), I pushed the result to #718. Would you like to give it a look? Then if that sounds good to you we can close this PR and roll with #718.

@gdhameeja

Copy link
Copy Markdown
Contributor Author

Closing this as there is another PR for this.
#718

@gdhameeja gdhameeja closed this Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Authentication flows should preserve history.

3 participants