Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
make it easy to extend HTTPHandler with custom connection. solves iss…
…ue 39826
  • Loading branch information
lorb committed Mar 2, 2020
commit 775e8f85ad4cecb78d55b293ed406cdd46d86443
21 changes: 16 additions & 5 deletions Lib/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1173,19 +1173,30 @@ def mapLogRecord(self, record):
"""
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.
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":
Expand Down