From 1aacba497bfb816d16dc39c09cae3ae17d6d74a2 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Sun, 29 Apr 2012 12:51:54 +0800 Subject: Fix Issue6085 - SimpleHTTPServer address_string to return client ip instead of client hostname --- Doc/library/http.server.rst | 7 +++++-- Lib/http/server.py | 13 ++----------- Misc/NEWS | 3 +++ 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Doc/library/http.server.rst b/Doc/library/http.server.rst index 06670b8..6665c93 100644 --- a/Doc/library/http.server.rst +++ b/Doc/library/http.server.rst @@ -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) diff --git a/Lib/http/server.py b/Lib/http/server.py index 18313cf..b6b2997 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -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: diff --git a/Misc/NEWS b/Misc/NEWS index 3b5cbda..83f2e3e 100644 --- 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. -- cgit v0.12