]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a default value to a getaddr() call in HTTPServerRequest.
authorBen Darnell <ben@bendarnell.com>
Fri, 18 Jul 2014 03:26:12 +0000 (23:26 -0400)
committerBen Darnell <ben@bendarnell.com>
Fri, 18 Jul 2014 03:26:12 +0000 (23:26 -0400)
Closes #1118.

tornado/httputil.py
tornado/test/httputil_test.py

index a67489725587193f9a4b853c28b0cdb206f009a1..1c5753822666ec40b9a5f1c3bd788b132c4f4b05 100644 (file)
@@ -335,7 +335,7 @@ class HTTPServerRequest(object):
 
         # set remote IP and protocol
         context = getattr(connection, 'context', None)
-        self.remote_ip = getattr(context, 'remote_ip')
+        self.remote_ip = getattr(context, 'remote_ip', None)
         self.protocol = getattr(context, 'protocol', "http")
 
         self.host = host or self.headers.get("Host") or "127.0.0.1"
index 1e84da76f0b8c74c61d7fee6bebfbd376894c468..8e0bf9824318566addb2d203f556a72f4e0155a9 100644 (file)
@@ -2,7 +2,7 @@
 
 
 from __future__ import absolute_import, division, print_function, with_statement
-from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp
+from tornado.httputil import url_concat, parse_multipart_form_data, HTTPHeaders, format_timestamp, HTTPServerRequest
 from tornado.escape import utf8
 from tornado.log import gen_log
 from tornado.testing import ExpectLog
@@ -253,3 +253,13 @@ class FormatTimestampTest(unittest.TestCase):
 
     def test_datetime(self):
         self.check(datetime.datetime.utcfromtimestamp(self.TIMESTAMP))
+
+
+# HTTPServerRequest is mainly tested incidentally to the server itself,
+# but this tests the parts of the class that can be tested in isolation.
+class HTTPServerRequestTest(unittest.TestCase):
+    def test_default_constructor(self):
+        # All parameters are formally optional, but uri is required
+        # (and has been for some time).  This test ensures that no
+        # more required parameters slip in.
+        HTTPServerRequest(uri='/')