Skip to content

Commit

Permalink
Web: get real ip (on proxy use)
Browse files Browse the repository at this point in the history
  • Loading branch information
treemo committed Jun 11, 2015
1 parent 16d52a1 commit 6988bbe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions circuits/web/tools.py
Expand Up @@ -13,6 +13,8 @@
from email.utils import formatdate
from datetime import datetime, timedelta
from email.generator import _make_boundary
from circuits import BaseComponent, handler
from circuits.web.wrappers import Host

mimetypes.init()
mimetypes.add_type("image/x-dwg", ".dwg")
Expand Down Expand Up @@ -449,3 +451,14 @@ def gzip(response, level=4, mime_types=("text/html", "text/plain",)):
return httperror(
response.request, response, 406, description="identity, gzip"
)


class BehindProxy(BaseComponent):
http_index = ['X-Real-IP', 'X-Forwarded-For']

@handler('request', priority=1)
def _on_request(self, req, *args):
for index in self.http_index:
real_ip = req.headers.get(index)
req.remote = Host(real_ip, '', real_ip)
return

0 comments on commit 6988bbe

Please sign in to comment.