def request(self, url, message, **kwargs):
"""Issues an HTTP request to a URL.
:param url: The URL.
:type url: ``string``
:param message: A dictionary with the format as described in
:class:`HttpLib`.
:type message: ``dict``
:param kwargs: Additional keyword arguments (optional). These arguments
are passed unchanged to the handler.
:type kwargs: ``dict``
:returns: A dictionary describing the response (see :class:`HttpLib` for
its structure).
:rtype: ``dict``
"""
response = self.handler(url, message, **kwargs)
response = record(response)
if 400 <= response.status:
raise HTTPError(response)
# Update the cookie with any HTTP request
# Initially, assume list of 2-tuples
key_value_tuples = response.headers
# If response.headers is a dict, get the key-value pairs as 2-tuples
# this is the case when using urllib2
if isinstance(response.headers, dict):
key_value_tuples = response.headers.items()
for key, value in key_value_tuples:
if key.lower() == "set-cookie":
_parse_cookies(value, self._cookies)
return response
# Converts an httplib response into a file-like object.
评论列表
文章目录