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

Skip to content

Commit 1aacba4

Browse files
committed
Fix Issue6085 - SimpleHTTPServer address_string to return client ip instead of client hostname
1 parent 0ce1649 commit 1aacba4

3 files changed

Lines changed: 10 additions & 13 deletions

File tree

Doc/library/http.server.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,11 @@ of which this module provides three different variants:
269269

270270
.. method:: address_string()
271271

272-
Returns the client address, formatted for logging. A name lookup is
273-
performed on the client's IP address.
272+
Returns the client address.
273+
274+
.. versionchanged:: 3.3
275+
Previously, a name lookup was performed. To avoid name resolution
276+
delays, it now always returns the IP address.
274277

275278

276279
.. class:: SimpleHTTPRequestHandler(request, client_address, server)

Lib/http/server.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,9 @@ def log_date_time_string(self):
558558
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
559559

560560
def address_string(self):
561-
"""Return the client address formatted for logging.
561+
"""Return the client address."""
562562

563-
This version looks up the full hostname using gethostbyaddr(),
564-
and tries to find a name that contains at least one dot.
565-
566-
"""
567-
568-
host, port = self.client_address[:2]
569-
return socket.getfqdn(host)
563+
return self.client_address[0]
570564

571565
# Essentially static class variables
572566

@@ -1040,9 +1034,6 @@ def run_cgi(self):
10401034
env['SCRIPT_NAME'] = scriptname
10411035
if query:
10421036
env['QUERY_STRING'] = query
1043-
host = self.address_string()
1044-
if host != self.client_address[0]:
1045-
env['REMOTE_HOST'] = host
10461037
env['REMOTE_ADDR'] = self.client_address[0]
10471038
authorization = self.headers.get("authorization")
10481039
if authorization:

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Core and Builtins
8181
Library
8282
-------
8383

84+
- Issue #6085: In http.server.py SimpleHTTPServer.address_string returns the
85+
client ip address instead client hostname. Patch by Charles-François Natali.
86+
8487
- Issue #14309: Deprecate time.clock(), use time.perf_counter() or
8588
time.process_time() instead.
8689

0 commit comments

Comments
 (0)