requests: Use the host in the redirect url, not the one in 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>
pull/972/head
黃昕暐 2024-12-06 13:43:24 +08:00 zatwierdzone przez Damien George
rodzic 42caaf14de
commit 43ad7c58fd
2 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -1,3 +1,3 @@
metadata(version="0.10.1", pypi="requests") metadata(version="0.10.2", pypi="requests")
package("requests") package("requests")

Wyświetl plik

@ -182,6 +182,8 @@ def request(
if redirect: if redirect:
s.close() s.close()
# Use the host specified in the redirect URL, as it may not be the same as the original URL.
headers.pop("Host", None)
if status in [301, 302, 303]: if status in [301, 302, 303]:
return request("GET", redirect, None, None, headers, stream) return request("GET", redirect, None, None, headers, stream)
else: else: