Skip to content

Add max_response_size to cap response body reads#7179

Closed
neilverma526-alt wants to merge 3 commits intopsf:mainfrom
neilverma526-alt:shipd-max-response-size
Closed

Add max_response_size to cap response body reads#7179
neilverma526-alt wants to merge 3 commits intopsf:mainfrom
neilverma526-alt:shipd-max-response-size

Conversation

@neilverma526-alt
Copy link
Copy Markdown

Adds max_response_size to requests.request and Session.request to cap response body reads.

  • Introduces requests.exceptions.ContentTooLarge.
  • Enforces limits based on bytes actually read (streaming raises during consumption via iter_content/.content).
  • Ensures connection is closed/released when limit exceeded to avoid pool deadlocks.
  • Keeps behavior unchanged when max_response_size is not provided.

Tests:

  • ./test.sh base
  • ./test.sh new

@neilverma526-alt neilverma526-alt marked this pull request as draft January 21, 2026 12:33
@neilverma526-alt neilverma526-alt marked this pull request as ready for review January 21, 2026 14:07
@nateprewitt
Copy link
Copy Markdown
Member

Hi @neilverma526-alt, you're free to do this in your code but this isn't something we'd internalize in Requests. If you're concerned about how much data you're reading, calling iter_content with a fixed sized chunks you're comfortable with would be the suggested approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants