Skip to content

Conversation

@tboy1337
Copy link

Summary

Fixes a bug in MockResponse.getheaders() method where it was not returning the headers list, resulting in None being returned instead.

Problem

The getheaders() method in the MockResponse class (used for cookie extraction) was missing a return statement, causing it to always return None instead of the actual headers list.

Solution

  • Added the missing return statement in src/requests/cookies.py line 121
  • Added comprehensive unit tests to verify the fix:
    • Test for successful header retrieval with multiple values
    • Test for empty list when no matching headers exist
    • Mock validation to ensure proper delegation to underlying HTTPMessage

Changes

  • Modified: src/requests/cookies.py - Added return statement to MockResponse.getheaders()
  • Added: Two unit tests in tests/test_requests.py:
    • test_mock_response_getheaders_returns_headers_list()
    • test_mock_response_getheaders_returns_empty_list()

Testing

All new tests pass and verify that:

  • The method correctly returns a list of headers when present
  • The method returns an empty list (not None) when no headers match
  • The underlying HTTPMessage.getheaders() is called with the correct arguments

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.

1 participant