]> granicus.if.org Git - python/commitdiff
Added Host and Content-type headers to requests sent by HTTPHandler (suggested by...
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 11 Oct 2005 13:15:31 +0000 (13:15 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Tue, 11 Oct 2005 13:15:31 +0000 (13:15 +0000)
Lib/logging/handlers.py

index 0801699a5406e104042ca334fe10ed6a6d83c8f1..0182dfede21c3c8573025532adc58cea1c334b2b 100644 (file)
@@ -854,7 +854,8 @@ class HTTPHandler(logging.Handler):
         """
         try:
             import httplib, urllib
-            h = httplib.HTTP(self.host)
+            host = self.host
+            h = httplib.HTTP(host)
             url = self.url
             data = urllib.urlencode(self.mapLogRecord(record))
             if self.method == "GET":
@@ -864,7 +865,15 @@ class HTTPHandler(logging.Handler):
                     sep = '?'
                 url = url + "%c%s" % (sep, data)
             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":
+                h.putheader("Content-type",
+                            "application/x-www-form-urlencoded")
                 h.putheader("Content-length", str(len(data)))
             h.endheaders()
             if self.method == "POST":