Skip to content
Myr

Added the possibility to access headers without fetching the whole body (fixes #86).

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jérémy Bethmont · committed by Jérémy Bethmont · parent d2ff0f4 · Browse files · 1 file+17 added−20 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+17 added−20 removed

  • other:+17 added−20 removed

1 file+17 added−20 removed

modified:requests/models.py+17 added-20 removed
149 unmodified lines
150 response.status_code = getattr(resp, 'code', None)151152 try:153 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))154 response.content = resp.read()154 response.read = resp.read155 response.close = resp.close156 except AttributeError:157 pass158158 if response.headers['content-encoding'] == 'gzip':159 try:160 response.content = zlib.decompress(response.content, 16+zlib.MAX_WBITS)161 except zlib.error:162 pass163164 # TODO: Support deflate165159 response.url = getattr(resp, 'url', None)160161 return response162
153 unmodified lines
316317 return self.sent318319327 def read(self, *args):328 return self.response.read()320330331321class Response(object):322 """The core :class:`Response <models.Response>` object. All323 :class:`Request <models.Request>` objects contain a324 :class:`response <models.Response>` attribute, which is an instance
3 unmodified lines
328 def __init__(self):329 #: Raw content of the response, in bytes.330 #: If ``content-encoding`` of response was set to ``gzip``, the331 #: response data will be automatically deflated.343 self.content = None332 self._content = None333 #: Integer Code of responded HTTP Status.334 self.status_code = None335 #: Case-insensitive Dictionary of Response Headers.336 #: For example, ``headers['content-encoding']`` will return the
21 unmodified lines
358 """Returns true if :attr:`status_code` is 'OK'."""359 return not self.error360361362 def __getattr__(self, name):363 """Read and returns the full stream when accessing to :attr: `content`"""364 if name == 'content':365 if self._content is not None:366 return self._content367 self._content = self.read()368 if self.headers.get('content-encoding', '') == 'gzip':369 try:370 self._content = zlib.decompress(self._content, 16+zlib.MAX_WBITS)371 except zlib.error:372 pass373 return self._content374375376 def raise_for_status(self):377 """Raises stored :class:`HTTPError` or :class:`URLError`, if one occured."""378 if self.error:379 raise self.error380378 def read(self, *args):379 """Returns :attr:`content`. Used for file-like object compatiblity."""381381 return self.content382383384382class AuthManager(object):383 """Requests Authentication Manager."""384385 def __new__(cls):
165 unmodified lines