-
Notifications
You must be signed in to change notification settings - Fork 1k
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
python-ecosys/requests/requests/__init__.py: Use the host in the redirect url, not the one in headers. #942
Conversation
The host in headers extracted from the original url may not be the same as the host in the redirect url. Poping out the host in headers force the code to use the host in the redirect url, otherwise the redirect may fail due to inconsistence of hosts in the original url and the redirect url. Signed-off-by: 黃昕暐 <meebox@gmail.com>
@@ -180,6 +180,9 @@ def request( | |||
|
|||
if redirect: | |||
s.close() | |||
# use the Host in the redirect URL | |||
if "Host" in headers: | |||
headers.pop("Host") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could use headers.pop("Host", None)
here to make it a little more efficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Use `headers.pop("Host", None)` instead of a `if` statement. Signed-off-by: 黃昕暐 <meebox@gmail.com>
… "Host" header in the redirect URL Update the comment to explain the reason for poping out "Host" header from headers. Ths host in the redirect URL may not be the same as the original URL, pop out "Host" in headers before redirect would force using the host specified in the redirect URL. Signed-off-by: 黃昕暐 <meebox@gmail.com>
Update the comment to explain the reason for poping out "Host" header from headers. Ths host in the redirect URL may not be the same as the original URL, pop out "Host" in headers before redirect would force using the host specified in the redirect URL. Signed-off-by: 黃昕暐 <meebox@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating, looks good now.
Rebased and merged in 43ad7c5 |
removing the host header when redirect
The host in headers extracted from the original url may not be the same as the host in the redirect url. It shoud use the host in the redirect url, not the one in the headers.