Skip to content

Conversation

@jcugat
Copy link
Contributor

@jcugat jcugat commented May 27, 2020

Fixes #822

I used Scheme "blah" not supported as the error message instead of URL scheme must be "http" or "https". used in other parts of the code. It makes more sense to show the actual invalid scheme since it's coming from the server and not something that the user specified.

I also tried the same test with allow_redirects=False but unfortunately when the response object is built, it needs a port which we can't derive from the custom scheme. Not sure how to solve this without changing the port definition of Url to allow a None port, ideas?

url = URL(location, allow_relative=True)

# Check that we can handle the scheme
if url.scheme and url.scheme not in ("http", "https"):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

In these kinds of cases, if it's a single-liner I'd often prefer not to introduce indirection. It's as clear as it can possibly be, and it's not a complicated expression.

@jcugat jcugat force-pushed the redirect-custom-scheme branch from 9160631 to c57f992 Compare May 27, 2020 19:32
Copy link
Contributor

@florimondmanca florimondmanca left a comment

Choose a reason for hiding this comment

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

Thanks! Sounds like an about right fix to me, waiting for an overhaul of scheme handling #954 and possibly mounting transports #977.

Happy to have someone else's opinion on this though :-)

Copy link
Contributor

@yeraydiazdiaz yeraydiazdiaz left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @jcugat!

@florimondmanca florimondmanca merged commit 093cb42 into encode:master May 28, 2020
@jcugat jcugat deleted the redirect-custom-scheme branch May 28, 2020 11:23
@lovelydinosaur lovelydinosaur mentioned this pull request May 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KeyError occurs when redirect to custom scheme(ex. market://)

4 participants