psf / psf/requests

Make response.next lazily computable.

Open
#4,123 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
54.3k
Forks
10.4k
Avg merge
16h 43m
Merged PRs (30d)
3

Description

When attempting to debug #4122 I attempted to use the standard method for debugging this, which is to set allow_redirects=False and to manually check the headers. Unfortunately, this no longer works since @kennethreitz shipped 2.15.0, as Requests now always computes the first redirect target in order to write it into Response.next. This makes it very frustrating to debug problems with Requests redirect following because it cannot be disabled, meaning that monkeypatching is required to prevent Requests blowing up.

I propose that we should either make response.next lazily computable, such that it is only calculated when actually requested, or we should remove it.

Expected Result

I expected that if allow_redirects=False was provided Requests would not run any of its redirect handling code.

Actual Result

It did.

Reproduction Steps

import requests
url = 'http://www.yftxt.com/plus/xiazai_yfx.php?open=2&id=12914&uhash=7fadfdb165fadc7362f9dc90'
requests.get(url, allow_redirects=False)

System Information

$ python -m requests.help
{
  "chardet": {
    "version": "3.0.3"
  },
  "cryptography": {
    "version": ""
  },
  "implementation": {
    "name": "CPython",
    "version": "3.6.0"
  },
  "platform": {
    "release": "16.7.0",
    "system": "Darwin"
  },
  "pyOpenSSL": {
    "openssl_version": "",
    "version": null
  },
  "requests": {
    "version": "2.17.3"
  },
  "system_ssl": {
    "version": "100020cf"
  },
  "urllib3": {
    "version": "1.21.1"
  },
  "using_pyopenssl": false
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the requests.get entry point and the redirect handling that populates Response.next, using the provided allow_redirects=False reproduction. Done means disabling redirects no longer performs redirect handling or computes the first redirect target, with coverage for the resulting Response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.