AsyncHttpResponse Class

An AsyncHttpResponse ABC.

Allows for the asynchronous streaming of data from the response.

Inheritance
azure.core.pipeline.transport._base._HttpResponseBase
AsyncHttpResponse
AsyncHttpResponse
AsyncHttpResponse

Constructor

AsyncHttpResponse(request: HttpRequest, internal_response: Any, block_size: int | None = None)

Parameters

Name Description
request
Required
internal_response
Required
block_size
Default value: None

Methods

body

Return the whole body as bytes in memory.

Sync implementer should load the body in memory if they can. Async implementer should rely on async load_body to have been called first.

parts

Assuming the content-type is multipart/mixed, will return the parts as an async iterator.

raise_for_status

Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.

stream_download

Generator for streaming response body data.

Should be implemented by sub-classes if streaming download is supported. Will return an asynchronous generator.

text

Return the whole body as a string.

body

Return the whole body as bytes in memory.

Sync implementer should load the body in memory if they can. Async implementer should rely on async load_body to have been called first.

body() -> bytes

Returns

Type Description

The whole body as bytes in memory.

parts

Assuming the content-type is multipart/mixed, will return the parts as an async iterator.

parts() -> AsyncIterator[AsyncHttpResponse]

Returns

Type Description

An async iterator of the parts

Exceptions

Type Description

If the content is not multipart/mixed

raise_for_status

Raises an HttpResponseError if the response has an error status code. If response is good, does nothing.

raise_for_status() -> None

stream_download

Generator for streaming response body data.

Should be implemented by sub-classes if streaming download is supported. Will return an asynchronous generator.

stream_download(pipeline: AsyncPipeline[HttpRequest, 'AsyncHttpResponse'], *, decompress: bool = True, **kwargs: Any) -> AsyncIteratorType[bytes]

Parameters

Name Description
pipeline
Required

The pipeline object

Keyword-Only Parameters

Name Description
decompress

If True which is default, will attempt to decode the body based on the content-encoding header.

Default value: True

Returns

Type Description

An async iterator of bytes

text

Return the whole body as a string.

text(encoding: str | None = None) -> str

Parameters

Name Description
encoding
str

The encoding to apply. If None, use "utf-8" with BOM parsing (utf-8-sig). Implementation can be smarter if they want (using headers or chardet).

Default value: None

Returns

Type Description
str

The whole body as a string.

See also

~body()