Skip to content

Commit a742480

Browse files
committed
bpo-37363: Add audit events to the http.client module
1 parent cdad272 commit a742480

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Doc/library/http.client.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,8 @@ HTTPConnection Objects
368368
this is called automatically when making a request if the client does not
369369
already have a connection.
370370

371+
.. audit-event:: http.client.connect self,host,port http.client.HTTPConnection.connect
372+
371373

372374
.. method:: HTTPConnection.close()
373375

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

442+
.. audit-event:: http.client.send self,data http.client.HTTPConnection.send
443+
440444

441445
.. _httpresponse-objects:
442446

Lib/http/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import io
7575
import re
7676
import socket
77+
import sys
7778
import collections.abc
7879
from urllib.parse import urlsplit
7980

@@ -931,6 +932,7 @@ def _tunnel(self):
931932

932933
def connect(self):
933934
"""Connect to the host and port specified in __init__."""
935+
sys.audit("http.client.connect", self, self.host, self.port)
934936
self.sock = self._create_connection(
935937
(self.host,self.port), self.timeout, self.source_address)
936938
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
@@ -978,8 +980,10 @@ def send(self, data):
978980
break
979981
if encode:
980982
datablock = datablock.encode("iso-8859-1")
983+
sys.audit("http.client.send", self, datablock)
981984
self.sock.sendall(datablock)
982985
return
986+
sys.audit("http.client.send", self, data)
983987
try:
984988
self.sock.sendall(data)
985989
except TypeError:

0 commit comments

Comments
 (0)