Kaydet (Commit) 1aacba49 authored tarafından Senthil Kumaran's avatar Senthil Kumaran

Fix Issue6085 - SimpleHTTPServer address_string to return client ip instead of client hostname

üst 0ce16496
...@@ -269,8 +269,11 @@ of which this module provides three different variants: ...@@ -269,8 +269,11 @@ of which this module provides three different variants:
.. method:: address_string() .. method:: address_string()
Returns the client address, formatted for logging. A name lookup is Returns the client address.
performed on the client's IP 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) .. class:: SimpleHTTPRequestHandler(request, client_address, server)
......
...@@ -558,15 +558,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): ...@@ -558,15 +558,9 @@ class BaseHTTPRequestHandler(socketserver.StreamRequestHandler):
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def address_string(self): def address_string(self):
"""Return the client address formatted for logging. """Return the client address."""
This version looks up the full hostname using gethostbyaddr(), return self.client_address[0]
and tries to find a name that contains at least one dot.
"""
host, port = self.client_address[:2]
return socket.getfqdn(host)
# Essentially static class variables # Essentially static class variables
...@@ -1040,9 +1034,6 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): ...@@ -1040,9 +1034,6 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
env['SCRIPT_NAME'] = scriptname env['SCRIPT_NAME'] = scriptname
if query: if query:
env['QUERY_STRING'] = 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] env['REMOTE_ADDR'] = self.client_address[0]
authorization = self.headers.get("authorization") authorization = self.headers.get("authorization")
if authorization: if authorization:
......
...@@ -81,6 +81,9 @@ Core and Builtins ...@@ -81,6 +81,9 @@ Core and Builtins
Library 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 - Issue #14309: Deprecate time.clock(), use time.perf_counter() or
time.process_time() instead. time.process_time() instead.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment