]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Remove new HTTPRequest.if_modified_since property.
authorBen Darnell <ben@bendarnell.com>
Mon, 23 Dec 2013 22:08:01 +0000 (17:08 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 23 Dec 2013 22:08:01 +0000 (17:08 -0500)
This property was unusual in that its getter returned a value its
setter would not accept, and was redundant with direct access to the
headers.

Use the property setters in the constructor instead of duplicating logic.

tornado/httpclient.py
tornado/test/httpclient_test.py

index ca0305fd3df1cd82ec1df0adcddd705efe848a54..9b42d401ad5fb465be55ec0ce535d97d73a375bd 100644 (file)
@@ -335,10 +335,11 @@ class HTTPRequest(object):
         .. versionadded:: 3.1
            The ``auth_mode`` argument.
         """
-        if headers is None:
-            headers = httputil.HTTPHeaders()
+        # Note that some of these attributes go through property setters
+        # defined below.
+        self.headers = headers
         if if_modified_since:
-            headers["If-Modified-Since"] = httputil.format_timestamp(
+            self.headers["If-Modified-Since"] = httputil.format_timestamp(
                 if_modified_since)
         self.proxy_host = proxy_host
         self.proxy_port = proxy_port
@@ -346,8 +347,7 @@ class HTTPRequest(object):
         self.proxy_password = proxy_password
         self.url = url
         self.method = method
-        self._headers = headers
-        self._body = utf8(body)
+        self.body = body
         self.auth_username = auth_username
         self.auth_password = auth_password
         self.auth_mode = auth_mode
@@ -358,9 +358,9 @@ class HTTPRequest(object):
         self.user_agent = user_agent
         self.use_gzip = use_gzip
         self.network_interface = network_interface
-        self._streaming_callback = stack_context.wrap(streaming_callback)
-        self._header_callback = stack_context.wrap(header_callback)
-        self._prepare_curl_callback = stack_context.wrap(prepare_curl_callback)
+        self.streaming_callback = streaming_callback
+        self.header_callback = header_callback
+        self.prepare_curl_callback = prepare_curl_callback
         self.allow_nonstandard_methods = allow_nonstandard_methods
         self.validate_cert = validate_cert
         self.ca_certs = ca_certs
@@ -380,14 +380,6 @@ class HTTPRequest(object):
         else:
             self._headers = value
 
-    @property
-    def if_modified_since(self):
-        return self.headers.get("If-Modified-Since")
-
-    @if_modified_since.setter
-    def if_modified_since(self, value):
-        self.headers["If-Modified-Since"] = httputil.format_timestamp(value)
-
     @property
     def body(self):
         return self._body
index 12a2981fe9ad02c11215a3c16b33f234716ee7dc..0ebdd8ddc3c966db0450131b28b585203f54a507 100644 (file)
@@ -508,22 +508,6 @@ class HTTPRequestTestCase(unittest.TestCase):
         request.headers = None
         self.assertEqual(request.headers, {})
 
-    def test_if_modified_since(self):
-        request = HTTPRequest(
-            'http://example.com',
-            if_modified_since=time.strptime("01 Jan 10", "%d %b %y")
-        )
-        self.assertEqual(request.if_modified_since,
-                         'Fri, 01 Jan 2010 00:00:00 GMT')
-
-    def test_if_modified_since_setter(self):
-        request = HTTPRequest('http://example.com')
-        request.if_modified_since = time.strptime("02 Jan 10", "%d %b %y")
-        self.assertEqual(
-            request._headers,
-            {'If-Modified-Since': 'Sat, 02 Jan 2010 00:00:00 GMT'}
-        )
-
     def test_body(self):
         request = HTTPRequest('http://example.com', body='foo')
         self.assertEqual(request.body, utf8('foo'))