Skip to content

Commit

Permalink
ensure that the socket is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
beliaev-maksim committed Nov 14, 2023
1 parent 437a37a commit c18f6d5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

* Reintroduced overloads for better typing in `CallList`.
* Added typing to `Call` attributes.
* Close unclosed socket (see #689)


0.24.0
Expand Down
25 changes: 12 additions & 13 deletions responses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,6 @@ def _form_response(
headers: Optional[Mapping[str, str]],
status: int,
) -> HTTPResponse:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as dummy_socket:
orig_response = http.client.HTTPResponse(sock=dummy_socket)

"""
The cookie handling functionality of the `requests` library relies on the response object
having an original response object with the headers stored in the `msg` attribute.
Expand All @@ -544,16 +541,18 @@ def _form_response(
introduce potential errors.
Therefore, we intentionally ignore type checking for this assignment.
"""
orig_response.msg = headers # type: ignore[assignment]

return HTTPResponse(
status=status,
reason=client.responses.get(status, None),
body=body,
headers=headers,
original_response=orig_response,
preload_content=False,
)
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as dummy_socket:
with http.client.HTTPResponse(sock=dummy_socket) as orig_response:
orig_response.msg = headers # type: ignore[assignment]

return HTTPResponse(
status=status,
reason=client.responses.get(status, None),
body=body,
headers=headers,
original_response=orig_response,
preload_content=False,
)


class Response(BaseResponse):
Expand Down

0 comments on commit c18f6d5

Please sign in to comment.