-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-130902 Add optional socket shutdown to close method of HTTPConnection class in http/client.py #130919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-130902 Add optional socket shutdown to close method of HTTPConnection class in http/client.py #130919
Changes from 16 commits
8097d96
1c819a6
d98c28e
3d8c39f
1484782
750f864
563afb9
7f0e156
bee6c39
07a2262
365e6a4
120e8fc
6324b64
88a3d96
52cd353
26a9b4d
bfff327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -1012,19 +1012,39 @@ def connect(self): | |||
| if self._tunnel_host: | ||||
| self._tunnel() | ||||
|
|
||||
| def close(self): | ||||
| """Close the connection to the HTTP server.""" | ||||
| def close(self, shutdown=False): | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add it in the Ref. cpython/Doc/library/socket.rst Line 1488 in b1b4f96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, shouldn't take too long There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Mr-Sunglasses Finally ready for review/ Added/updated docs for the close method of HTTPConnection class as well as added back a modifed docstring in http/client.py! |
||||
| """Close the connection to the HTTP server. | ||||
| :param shutdown: If True, perform an explicit shutdown of the socket before closing. Defaults to False. | ||||
| :type shutdown: bool, optional | ||||
| """ | ||||
| self.__state = _CS_IDLE | ||||
| try: | ||||
| sock = self.sock | ||||
| if sock: | ||||
| self.sock = None | ||||
| sock.close() # close it manually... there may be other refs | ||||
| if shutdown: | ||||
| try: | ||||
| sock.shutdown(socket.SHUT_RDWR) | ||||
| except OSError as e: | ||||
| print(f"Socket shutdown error: {e}", file=sys.stderr) | ||||
| except Exception as e: | ||||
| print(f"Unexpected error during socket shutdown: {e}", file=sys.stderr) | ||||
| try: | ||||
| sock.close() | ||||
| except OSError as e: | ||||
| print(f"Socket close error: {e}", file=sys.stderr) | ||||
| except Exception as e: | ||||
| print(f"Unexpected error during socket close: {e}", file=sys.stderr) | ||||
| finally: | ||||
| response = self.__response | ||||
| if response: | ||||
| self.__response = None | ||||
| response.close() | ||||
| try: | ||||
| response.close() | ||||
| except OSError as e: | ||||
| print(f"Response close error: {e}", file=sys.stderr) | ||||
| except Exception as e: | ||||
| print(f"Unexpected error during response close: {e}", file=sys.stderr) | ||||
|
|
||||
| def send(self, data): | ||||
| """Send 'data' to the server. | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Issue: :gh:`130902` | ||
|
|
||
|
|
||
| Modifies the :meth:`http.client.HTTPConnection.close` of :class:`http.client.HTTPConnection` to include an optional socket ``shutdown``, improving functionality with error handling. |
Uh oh!
There was an error while loading. Please reload this page.