response#

Summary#

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

A dataclass containing cached response information, used for serialization.

CachedStreamReader([body])

A StreamReader loaded from previously consumed response content.

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=b'', content=None, links=_Nothing.NOTHING, cookies=_Nothing.NOTHING, created_at=_Nothing.NOTHING, encoding='utf-8', expires=None, raw_headers=_Nothing.NOTHING, real_url=None, history=_Nothing.NOTHING, last_used=_Nothing.NOTHING)#

Bases: HeadersMixin

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.

Parameters:
_body: Any#
_content: StreamReader | None#
property _headers: CIMultiDictProxy[str]#
property _released#
close()#
property closed: bool#
property connection#
property content: aiohttp.StreamReader#
property content_disposition: aiohttp.ContentDisposition | None#

Get Content-Disposition headers, if any

cookies: SimpleCookie#
created_at: datetime#
encoding: str#
expires: datetime | None#
property from_cache#
async classmethod from_client_response(client_response, expires=None)#

Convert a ClientResponse into a CachedReponse

Parameters:
get_encoding()#
property headers: CIMultiDictProxy[str]#

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

history: Iterable#
property host: str#
property is_expired: bool#

Determine if this cached response is expired

async json(encoding=None, **kwargs)#

Read and decode JSON response

Parameters:

encoding (Optional[str]) –

Return type:

Optional[dict[str, Any]]

last_used: datetime#

Convert stored links into the format returned by ClientResponse.links

method: str#
property ok: bool#

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

raise_for_status()#
raw_headers: RawHeaders#
async read()#

Read response payload.

Return type:

bytes

real_url: StrOrURL#
reason: str#
release()#
property request_info: aiohttp.RequestInfo#
reset()#

Reset the stream reader to re-read a streamed response

async start()#
status: int#
async terminate()#
async text(encoding=None, errors='strict')#

Read response payload and decode

Parameters:
Return type:

str

url: URL#
version: str#
async wait_for_close()#
class CachedStreamReader(body=None)#

Bases: StreamReader

A StreamReader loaded from previously consumed response content. This feeds cached data into the stream so it can support all the same behavior as the original stream: async iteration, chunked reads, etc.

Parameters:

body (Optional[bytes]) –

_to_str_tuples(data)#
Parameters:

data (Mapping) –

Return type:

List[Tuple[str, str]]

_to_url_multidict(data)#
Parameters:

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

Return type:

MultiDict

set_response_defaults(response)#

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

Parameters:

response (Union[ClientResponse, CachedResponse]) –

Return type:

Union[ClientResponse, CachedResponse]