psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Different default values for "allow_redirects" for HEAD http method #6723

Closed paulusbrand closed 5 months ago

paulusbrand commented 5 months ago

A HEAD request can be performed in two ways. Using the requests.head method or the requests.request method. But both have different default values for "allow_redirects".

Expected Result

Both ways of performing HEAD requests have the same default behavior.

Actual Result

requests.head(url) has allow_redirects disabled by default. requests.request("HEAD", url) has allow_redirects enabled by default.

Reproduction Steps

import requests

# HEAD request with default allow_redirects False
r = requests.head("http://test_site.com")

# HEAD request with default allow_redirects True
r = requests.request("HEAD", "http://test_site.com")

System Information

$ python -m requests.help
{
  "chardet": {
    "version": null
  },
  "charset_normalizer": {
    "version": "3.3.2"
  },
  "cryptography": {
    "version": ""
  },
  "idna": {
    "version": "3.7"
  },
  "implementation": {
    "name": "CPython",
    "version": "3.12.2"
  },
  "platform": {
    "release": "6.8.2-gentoo",
    "system": "Linux"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.31.0"
  },
  "system_ssl": {
    "version": "300000d0"
  },
  "urllib3": {
    "version": "2.2.1"
  },
  "using_charset_normalizer": true,
  "using_pyopenssl": false
}
sigmavirus24 commented 5 months ago

This is expected. The request method means you want to explicitly do things differently so you don't get the per-method behaviors otherwise defined

paulusbrand commented 5 months ago

@sigmavirus24 thanks! The reason i have to use requests.request is because there are no methods to perform TRACE and CONNECT http requests. For instance fir a GET request there is requests.get. For PUT there is requests.put. No such method exists for CONNECT and TRACE. Is this also intentional?

sigmavirus24 commented 5 months ago

Yes. These have all been discussed at I've point it another in various issues that are all closed

paulusbrand commented 5 months ago

https://github.com/psf/requests/pull/6209