Skip to content

Commit

Permalink
Fix redirect HTTP method handling (#3577)
Browse files Browse the repository at this point in the history
Authored by: coletdjnz
  • Loading branch information
coletdjnz committed May 2, 2022
1 parent b4f5366 commit afac4ca
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion yt_dlp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,9 +1587,21 @@ def redirect_request(self, req, fp, code, msg, headers, newurl):
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):
Expand Down

0 comments on commit afac4ca

Please sign in to comment.