With urllib3>=2, mocking HEAD responses with content-length header set requires a body with the right length, otherwise an IncompleteRead is raised. This should not be the case since HEAD responses do not have bodies.
Test fails with requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read, 11 more expected)', IncompleteRead(0 bytes read, 11 more expected)).
Describe the bug
With
urllib3>=2
, mocking HEAD responses with content-length header set requires a body with the right length, otherwise anIncompleteRead
is raised. This should not be the case since HEAD responses do not have bodies.Additional context
The fix is probably to pass the request method to
HTTPResponse
when forming the response. See the code around https://github.com/urllib3/urllib3/blob/733f638a2faa02b4ff8a9f3b5668949d39396b8b/src/urllib3/response.py#L624.Version of
responses
0.25.0
Steps to Reproduce
Run
pytest
onExpected Result
Test passes, like with
urllib3<2
.Actual Result
Test fails with
requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read, 11 more expected)', IncompleteRead(0 bytes read, 11 more expected))
.