]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix Issue6085 - SimpleHTTPServer address_string to return client ip instead of client...
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Apr 2012 04:51:54 +0000 (12:51 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 29 Apr 2012 04:51:54 +0000 (12:51 +0800)
Doc/library/http.server.rst
Lib/http/server.py
Misc/NEWS

index 06670b8d48fd4d10e5c21adc462d677645bcd279..6665c93caf55bbeec4eab77264d40bc2af3212c9 100644 (file)
@@ -269,8 +269,11 @@ of which this module provides three different variants:
 
    .. method:: address_string()
 
-      Returns the client address, formatted for logging. A name lookup is
-      performed on the client's IP address.
+      Returns the client address.
+
+      .. versionchanged:: 3.3
+         Previously, a name lookup was performed. To avoid name resolution
+         delays, it now always returns the IP address.
 
 
 .. class:: SimpleHTTPRequestHandler(request, client_address, server)
index 18313cffad5a6eb99fc47471b0d56ef94f2d2170..b6b2997fbf7b3b7ba7e71a33f6e8f5c3779a48f7 100644 (file)
@@ -558,15 +558,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
                  'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
 
     def address_string(self):
-        """Return the client address formatted for logging.
+        """Return the client address."""
 
-        This version looks up the full hostname using gethostbyaddr(),
-        and tries to find a name that contains at least one dot.
-
-        """
-
-        host, port = self.client_address[:2]
-        return socket.getfqdn(host)
+        return self.client_address[0]
 
     # Essentially static class variables
 
@@ -1040,9 +1034,6 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
         env['SCRIPT_NAME'] = scriptname
         if query:
             env['QUERY_STRING'] = query
-        host = self.address_string()
-        if host != self.client_address[0]:
-            env['REMOTE_HOST'] = host
         env['REMOTE_ADDR'] = self.client_address[0]
         authorization = self.headers.get("authorization")
         if authorization:
index 3b5cbda26de465c6a1f09f8655eab067621c157c..83f2e3ea04e883cc5f9f59f3b121946744ff7867 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -81,6 +81,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #6085: In http.server.py SimpleHTTPServer.address_string returns the
+  client ip address instead client hostname. Patch by Charles-François Natali.
+
 - Issue #14309: Deprecate time.clock(), use time.perf_counter() or
   time.process_time() instead.