8000 bpo-37363: Add audit events to the `http.client` module by gousaiyang · Pull Request #21321 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-37363: Add audit events to the http.client module #21321

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

Merged
merged 4 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-37363: Add audit events to the http.client module
  • Loading branch information
gousaiyang committed Apr 21, 2021
commit a7424802045889b680b12d619b8ffa179a5f6d0b
4 changes: 4 additions & 0 deletions Doc/library/http.client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ HTTPConnection Objects
this is called automatically when making a request if the client does not
already have a connection.

.. audit-event:: http.client.connect self,host,port http.client.HTTPConnection.connect


.. method:: HTTPConnection.close()

Expand Down Expand Up @@ -437,6 +439,8 @@ also send your request step by step, by using the four functions below.
:meth:`endheaders` method has been called and before :meth:`getresponse` is
called.

.. audit-event:: http.client.send self,data http.client.HTTPConnection.send


.. _httpresponse-objects:

Expand Down
4 changes: 4 additions & 0 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import io
import re
import socket
import sys
import collections.abc
from urllib.parse import urlsplit

Expand Down Expand Up @@ -931,6 +932,7 @@ def _tunnel(self):

def connect(self):
"""Connect to the host and port specified in __init__."""
sys.audit("http.client.connect", self, self.host, self.port)
self.sock = self._create_connection(
(self.host,self.port), self.timeout, self.source_address)
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
Expand Down Expand Up @@ -978,8 +980,10 @@ def send(self, data):
break
if encode:
datablock = datablock.encode("iso-8859-1")
sys.audit("http.client.send", self, datablock)
self.sock.sendall(datablock)
return
sys.audit("http.client.send", self, data)
try:
self.sock.sendall(data)
except TypeError:
Expand Down
0