From: Ben Darnell Date: Sun, 8 Mar 2015 14:33:40 +0000 (-0400) Subject: Make _request_summary handle remote_ip of None. X-Git-Tag: v4.2.0b1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e49a0c285d1452c2d6a5cd53839aca33b6ea6e70;p=thirdparty%2Ftornado.git Make _request_summary handle remote_ip of None. HTTPServerRequest has a default of None here although it is set by both HTTPServer and WSGIAdapter. --- diff --git a/tornado/test/web_test.py b/tornado/test/web_test.py index d7a11187f..f3c8505ad 100644 --- a/tornado/test/web_test.py +++ b/tornado/test/web_test.py @@ -2512,3 +2512,18 @@ class CacheTest(WebTestCase): headers={'If-None-Match': etags} ) self.assertEqual(response.code, status_code) + + +@wsgi_safe +class RequestSummaryTest(SimpleHandlerTestCase): + class Handler(RequestHandler): + def get(self): + # remote_ip is optional, although it's set by + # both HTTPServer and WSGIAdapter. + # Clobber it to make sure it doesn't break logging. + self.request.remote_ip = None + self.finish(self._request_summary()) + + def test_missing_remote_ip(self): + resp = self.fetch("/") + self.assertEqual(resp.body, b"GET / (None)") diff --git a/tornado/web.py b/tornado/web.py index 6de42d27d..62f3779df 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -1432,8 +1432,8 @@ class RequestHandler(object): self.application.log_request(self) def _request_summary(self): - return self.request.method + " " + self.request.uri + \ - " (" + self.request.remote_ip + ")" + return "%s %s (%s)" % (self.request.method, self.request.uri, + self.request.remote_ip) def _handle_request_exception(self, e): if isinstance(e, Finish):