.. 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
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
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
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
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'))