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

python-ecosys/requests/requests/__init__.py: Use the host in the redirect url, not the one in headers. #942

Closed
wants to merge 5 commits into from

Conversation

codemee
Copy link
Contributor

@codemee codemee commented Dec 6, 2024

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.

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>
@codemee codemee changed the title Use the host in the redirect url, not the one in headers. python-ecosys/requests/requests/__init__.py: Use the host in the redirect url, not the one in headers. Dec 6, 2024
@@ -180,6 +180,9 @@ def request(

if redirect:
s.close()
# use the Host in the redirect URL
if "Host" in headers:
headers.pop("Host")
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks.

codemee added 4 commits April 11, 2025 13:41
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>
Copy link
Member

@dpgeorge dpgeorge left a 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.

@dpgeorge
Copy link
Member

Rebased and merged in 43ad7c5

@dpgeorge dpgeorge closed this Apr 12, 2025
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.

None yet

2 participants