Changeset 3602
- Timestamp:
- 08/17/06 22:12:36 (2 years ago)
- Files:
-
- django/trunk/django/middleware/http.py (modified) (1 diff)
- django/trunk/docs/middleware.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/middleware/http.py
r3171 r3602 36 36 37 37 return response 38 39 class SetRemoteAddrFromForwardedFor(object): 40 """ 41 Middleware that sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, if the 42 latter is set. This is useful if you're sitting behind a reverse proxy that 43 causes each request's REMOTE_ADDR to be set to 127.0.0.1. 44 45 Note that this does NOT validate HTTP_X_FORWARDED_FOR. If you're not behind 46 a reverse proxy that sets HTTP_X_FORWARDED_FOR automatically, do not use 47 this middleware. Anybody can spoof the value of HTTP_X_FORWARDED_FOR, and 48 because this sets REMOTE_ADDR based on HTTP_X_FORWARDED_FOR, that means 49 anybody can "fake" their IP address. Only use this when you can absolutely 50 trust the value of HTTP_X_FORWARDED_FOR. 51 """ 52 def process_request(self, request): 53 try: 54 real_ip = request.META['HTTP_X_FORWARDED_FOR'] 55 except KeyError: 56 return None 57 else: 58 # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs. 59 # Take just the first one. 60 real_ip = real_ip.split(",")[0] 61 request.META['REMOTE_ADDR'] = real_ip django/trunk/docs/middleware.txt
r2980 r3602 64 64 redirected to ``foo.com/bar/``, but ``foo.com/bar/file.txt`` is passed 65 65 through unchanged. 66 66 67 67 If ``PREPEND_WWW`` is ``True``, URLs that lack a leading "www." will be 68 68 redirected to the same URL with a leading "www." … … 101 101 Also removes the content from any response to a HEAD request and sets the 102 102 ``Date`` and ``Content-Length`` response-headers. 103 104 django.middleware.http.SetRemoteAddrFromForwardedFor 105 ---------------------------------------------------- 106 107 **New in Django development version** 108 109 Sets ``request['REMOTE_ADDR']`` based on ``request.['HTTP_X_FORWARDED_FOR']``, 110 if the latter is set. This is useful if you're sitting behind a reverse proxy 111 that causes each request's ``REMOTE_ADDR`` to be set to ``127.0.0.1``. 112 113 **Important note:** This does NOT validate ``HTTP_X_FORWARDED_FOR``. If you're 114 not behind a reverse proxy that sets ``HTTP_X_FORWARDED_FOR`` automatically, do 115 not use this middleware. Anybody can spoof the value of 116 ``HTTP_X_FORWARDED_FOR``, and because this sets ``REMOTE_ADDR`` based on 117 ``HTTP_X_FORWARDED_FOR``, that means anybody can "fake" their IP address. Only 118 use this when you can absolutely trust the value of ``HTTP_X_FORWARDED_FOR``. 103 119 104 120 django.contrib.sessions.middleware.SessionMiddleware
