def test_get_ip_3_proxies(self): Config.num_proxies = 3 headers = {"X-Forwarded-For": "1.2.3.4, 5.6.7.8, 8.8.8.8"} env = EnvironBuilder(headers=headers).get_environ() env["REMOTE_ADDR"] = "6.6.6.6" request = Request(env) ip = BaseHandler.get_ip(request) self.assertEqual("1.2.3.4", ip)
def wsgi_app(self, environ, start_response): route = self.router.bind_to_environ(environ) request = Request(environ) try: endpoint, args = route.match() except HTTPException: Logger.warning("HTTP_ERROR", "%s %s %s 404" % (BaseHandler.get_ip(request), request.method, request.url)) return NotFound() controller, action = endpoint.split("#") return self.handlers[controller].handle(action, args, request)
def test_get_ip_no_proxies(self): Config.num_proxies = 0 request = Request(Environ(REMOTE_ADDR="1.2.3.4")) ip = BaseHandler.get_ip(request) self.assertEqual("1.2.3.4", ip)