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

Fix redirect HTTP method handling #3577

Merged
merged 5 commits into from May 2, 2022

Conversation

coletdjnz
Copy link
Member

@coletdjnz coletdjnz commented Apr 28, 2022

Please follow the guide below

  • You will be asked some questions, please read them carefully and answer honestly
  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])
  • Use Preview tab to see how your pull request will actually look like

Before submitting a pull request make sure you have:

In order to be accepted and merged into yt-dlp each piece of code must be in public domain or released under Unlicense. Check one of the following options:

  • I am the original author of this code and I am willing to release it under Unlicense
  • I am not the original author of this code but it is in public domain or released under Unlicense (provide reliable evidence)

What is the purpose of your pull request?

  • Bug fix
  • Improvement
  • New extractor
  • New feature

Description of your pull request and other information

Backported from #2861

Currently YoutubeDLRedirectHandler (which is based off the urllib redirect handler) makes all redirect requests with GET method, regardless of the original method and status code. This behaviour is inconsistent with standards and what browsers usually do.

This PR brings the method handling in line with RFC7231 and RFC7538 and what browsers tend to do. Requests v3 also does essentially the same thing.

This also fixes 307 & 308 redirects (they must retain the original method) - python/cpython#91306

The main changes are:

  • by default, do not change method on redirect
  • 303 uses GET (except for HEAD)
  • 301 and 302 should change to GET from POST

Urllib by default changes method to GET for every redirect
@coletdjnz coletdjnz added the bug Bug that is not site-specific label Apr 28, 2022
@coletdjnz coletdjnz changed the title Fix YoutubeDLRedirectHandler redirect method handling Fix redirect method handling Apr 28, 2022
@coletdjnz coletdjnz changed the title Fix redirect method handling Fix redirect HTTP method handling Apr 28, 2022
@pukkandan pukkandan merged commit afac4ca into yt-dlp:master May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that is not site-specific
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants