[Zope-Checkins] CVS: Zope/lib/python/ZPublisher - HTTPRequest.py:1.81.2.2.6.2
Toby Dickenson
tdickenson@geminidataloggers.com
Tue, 31 Dec 2002 07:09:40 -0500
Update of /cvs-repository/Zope/lib/python/ZPublisher
In directory cvs.zope.org:/tmp/cvs-serv18908/lib/python/ZPublisher
Modified Files:
Tag: toby-http-forwarded-for-branch
HTTPRequest.py
Log Message:
implemented Brians proposal for a getClientAddr method
=== Zope/lib/python/ZPublisher/HTTPRequest.py 1.81.2.2.6.1 => 1.81.2.2.6.2 ===
--- Zope/lib/python/ZPublisher/HTTPRequest.py:1.81.2.2.6.1 Wed Oct 23 10:59:32 2002
+++ Zope/lib/python/ZPublisher/HTTPRequest.py Tue Dec 31 07:09:38 2002
@@ -228,6 +228,11 @@
del self.other[x]
self._urls = ()
+ def getClientAddr(self):
+ """ The IP address of the client.
+ """
+ return self._client_addr
+
def __init__(self, stdin, environ, response, clean=0):
self._orig_env=environ
# Avoid the overhead of scrubbing the environment in the
@@ -253,12 +258,15 @@
self._steps=[]
self._lazies={}
- if environ.has_key('HTTP_X_FORWARDED_FOR') and environ.has_key('REMOTE_ADDR'):
- if environ['REMOTE_ADDR'] in trusted_proxies:
+
+ if environ.has_key('REMOTE_ADDR'):
+ self._client_addr = environ['REMOTE_ADDR']
+ if environ.has_key('HTTP_X_FORWARDED_FOR') and self._client_addr in trusted_proxies:
# REMOTE_ADDR is one of our trusted local proxies. Not really very remote at all.
# The proxy can tell us the IP of the real remote client in the forwarded-for header
- environ['HTTP_X_FORWARDED_BY'] = environ['REMOTE_ADDR']
- environ['REMOTE_ADDR'] = environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()
+ self._client_addr = environ['HTTP_X_FORWARDED_FOR'].split(',')[-1].strip()
+ else:
+ self._client_addr = ''
################################################################
# Get base info first. This isn't likely to cause