response

Summary

CachedResponse(method, reason, status, url, …)

A dataclass containing cached response information, used for serialization.

set_response_defaults(response)

Set some default CachedResponse values on a ClientResponse object, so they can be expected to always be present

Module Contents

class CachedResponse(method, reason, status, url, version, body=None, links=NOTHING, cookies=None, created_at=NOTHING, encoding=None, expires=None, raw_headers=NOTHING, real_url=None, history=NOTHING, last_used=NOTHING)

Bases: object

A dataclass containing cached response information, used for serialization. It will mostly behave the same as a aiohttp.ClientResponse that has been read, with some additional cache-related info.

_body
property _released
property content_disposition

Get Content-Disposition headers, if any

Return type

Optional[ContentDisposition]

cookies
created_at
encoding
expires
property from_cache
async classmethod from_client_response(client_response, expires=None)

Convert a ClientResponse into a CachedReponse

Parameters
  • client_response (aiohttp.client_reqrep.ClientResponse) –

  • expires (Optional[datetime.datetime]) –

get_encoding()
property headers

Get headers as an immutable, case-insensitive multidict from raw headers

Return type

CIMultiDictProxy

history
property host
Return type

str

property is_expired

Determine if this cached response is expired

Return type

bool

async json(encoding=None, **kwargs)

Read and decode JSON response

Return type

Optional[Dict[str, Any]]

Parameters

encoding (Optional[str]) –

last_used

Convert stored links into the format returned by ClientResponse.links

Return type

MultiDictProxy

method
property ok

Returns True if status is less than 400, False if not

Return type

bool

raise_for_status()
raw_headers
async read()

Read response payload.

Return type

bytes

real_url
reason
release()

No-op function for compatibility with ClientResponse

property request_info
Return type

RequestInfo

status
async text(encoding=None, errors='strict')

Read response payload and decode

Return type

str

Parameters
  • encoding (Optional[str]) –

  • errors (str) –

url
version
_to_str_tuples(data)
Return type

List[Tuple[str, str]]

Parameters

data (Mapping) –

_to_url_multidict(data)
Return type

MultiDict

Parameters

data (List[Tuple[str, str]]) –

set_response_defaults(response)

Set some default CachedResponse values on a ClientResponse object, so they can be expected to always be present

Return type

Union[ClientResponse, CachedResponse]

Parameters

response (Union[aiohttp.client_reqrep.ClientResponse, aiohttp_client_cache.response.CachedResponse]) –