mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Added Host and Content-type headers to requests sent by HTTPHandler (suggested by Steven Vereecken)
This commit is contained in:
parent
116078f0bb
commit
b79350601b
1 changed files with 10 additions and 1 deletions
|
@ -854,7 +854,8 @@ class HTTPHandler(logging.Handler):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
import httplib, urllib
|
import httplib, urllib
|
||||||
h = httplib.HTTP(self.host)
|
host = self.host
|
||||||
|
h = httplib.HTTP(host)
|
||||||
url = self.url
|
url = self.url
|
||||||
data = urllib.urlencode(self.mapLogRecord(record))
|
data = urllib.urlencode(self.mapLogRecord(record))
|
||||||
if self.method == "GET":
|
if self.method == "GET":
|
||||||
|
@ -864,7 +865,15 @@ class HTTPHandler(logging.Handler):
|
||||||
sep = '?'
|
sep = '?'
|
||||||
url = url + "%c%s" % (sep, data)
|
url = url + "%c%s" % (sep, data)
|
||||||
h.putrequest(self.method, url)
|
h.putrequest(self.method, url)
|
||||||
|
# support multiple hosts on one IP address...
|
||||||
|
# need to strip optional :port from host, if present
|
||||||
|
i = string.find(host, ":")
|
||||||
|
if i >= 0:
|
||||||
|
host = host[:i]
|
||||||
|
h.putheader("Host", host)
|
||||||
if self.method == "POST":
|
if self.method == "POST":
|
||||||
|
h.putheader("Content-type",
|
||||||
|
"application/x-www-form-urlencoded")
|
||||||
h.putheader("Content-length", str(len(data)))
|
h.putheader("Content-length", str(len(data)))
|
||||||
h.endheaders()
|
h.endheaders()
|
||||||
if self.method == "POST":
|
if self.method == "POST":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue