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

Improve error when redirecting with custom schemes #1002

Merged
merged 1 commit into from
May 28, 2020

Conversation

jcugat
Copy link
Member

@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?

@@ -322,6 +322,10 @@ def redirect_url(self, request: Request, response: Response) -> URL:

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
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Member

@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
@tomchristie tomchristie 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