summaryrefslogtreecommitdiffstats
path: root/Lib/logging
diff options
context:
space:
mode:
authorl0rb <lorbritzer@yahoo.de>2020-03-04 10:49:51 (GMT)
committerGitHub <noreply@github.com>2020-03-04 10:49:51 (GMT)
commit22a9a546ff3bf2a63d77ca1e5494e758bc59132f (patch)
tree7014df0897d175235e811a8bcbb775f10baced39 /Lib/logging
parentbe501ca2419a91546dea85ef4f36945545458589 (diff)
downloadcpython-22a9a546ff3bf2a63d77ca1e5494e758bc59132f.zip
cpython-22a9a546ff3bf2a63d77ca1e5494e758bc59132f.tar.gz
cpython-22a9a546ff3bf2a63d77ca1e5494e758bc59132f.tar.bz2
bpo-39826: add getConnection() hook to logging HTTPHandler (GH-18745)
Diffstat (limited to 'Lib/logging')
-rw-r--r--Lib/logging/handlers.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 047798f..4a120e9 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1173,6 +1173,20 @@ class HTTPHandler(logging.Handler):
"""
return record.__dict__
+ def getConnection(self, host, secure):
+ """
+ get a HTTP[S]Connection.
+
+ Override when a custom connection is required, for example if
+ there is a proxy.
+ """
+ import http.client
+ if secure:
+ connection = http.client.HTTPSConnection(host, context=self.context)
+ else:
+ connection = http.client.HTTPConnection(host)
+ return connection
+
def emit(self, record):
"""
Emit a record.
@@ -1180,12 +1194,9 @@ class HTTPHandler(logging.Handler):
Send the record to the Web server as a percent-encoded dictionary
"""
try:
- import http.client, urllib.parse
+ import urllib.parse
host = self.host
- if self.secure:
- h = http.client.HTTPSConnection(host, context=self.context)
- else:
- h = http.client.HTTPConnection(host)
+ h = self.getConnection(host, self.secure)
url = self.url
data = urllib.parse.urlencode(self.mapLogRecord(record))
if self.method == "GET":