diff options
author | coletdev <coletdjnz@protonmail.com> | 2022-05-02 15:40:26 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-01 20:40:26 -0700 |
commit | afac4caa7db30804bebac33e53c3cb0237958224 (patch) | |
tree | 72c1df07ad0aef871dadf5ad6927fd3166a72afe /yt_dlp/utils.py | |
parent | b4f536626aa0e9279869b0ed3506fcf5ab7ed6d2 (diff) | |
download | hypervideo-pre-afac4caa7db30804bebac33e53c3cb0237958224.tar.lz hypervideo-pre-afac4caa7db30804bebac33e53c3cb0237958224.tar.xz hypervideo-pre-afac4caa7db30804bebac33e53c3cb0237958224.zip |
Fix redirect HTTP method handling (#3577)
Authored by: coletdjnz
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index e25a112d3..5c83b92b4 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -1587,9 +1587,21 @@ class YoutubeDLRedirectHandler(compat_urllib_request.HTTPRedirectHandler): CONTENT_HEADERS = ("content-length", "content-type") # NB: don't use dict comprehension for python 2.6 compatibility newheaders = {k: v for k, v in req.headers.items() if k.lower() not in CONTENT_HEADERS} + + # A 303 must either use GET or HEAD for subsequent request + # https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.4 + if code == 303 and m != 'HEAD': + m = 'GET' + # 301 and 302 redirects are commonly turned into a GET from a POST + # for subsequent requests by browsers, so we'll do the same. + # https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.2 + # https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.3 + if code in (301, 302) and m == 'POST': + m = 'GET' + return compat_urllib_request.Request( newurl, headers=newheaders, origin_req_host=req.origin_req_host, - unverifiable=True) + unverifiable=True, method=m) def extract_timezone(date_str): |