wasat.response
Response class for Gemini protocol requests.
ReaderProtocol
Response
Response(
status: StatusCode,
meta: str,
reader: ReaderProtocol | None = None,
)
Represents a response from a Gemini server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
StatusCode
|
The Gemini status code. |
required |
|
str
|
The extra metadata line. |
required |
|
ReaderProtocol | None
|
The stream reader for reading the response body. |
None
|
content_type
property
content_type: str
The base content type (e.g., 'text/gemini' or 'text/plain').
meta
property
meta: str
The extra info/meta string from the response line.
For status 20, this is the MIME type. For other status codes, it contains error messages, instructions, or redirect URIs.
mime_type
property
mime_type: str
The raw MIME type of the response.
Only relevant for 2x SUCCESS status codes. Defaults to 'text/gemini; charset=utf-8'.
__aexit__
async
__aexit__(
exception_type: type[BaseException] | None,
exception_value: BaseException | None,
exception_traceback: object,
) -> None
Exit the async context manager and close the connection.
close
async
close() -> None
Close the underlying connection if it is still open.
iter_chunks
async
iter_chunks(chunk_size: int = 4096) -> AsyncIterator[bytes]
Iterate over the response body in chunks as they arrive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int
|
The maximum size of each chunk. |
4096
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[bytes]
|
Bytes chunks from the response body. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the server connection drops during reading. |
read
async
read() -> bytes
Read and return the entire response body.
Returns:
| Type | Description |
|---|---|
bytes
|
The raw response body bytes. |
Raises:
| Type | Description |
|---|---|
ConnectionError
|
If the server connection drops during reading. |
text
async
Read and return the entire response body as a decoded string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
The text encoding to use. If None, uses the charset from the response MIME type. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The decoded response body text. |
Raises:
| Type | Description |
|---|---|
ProtocolError
|
If the response body cannot be decoded using the specified encoding. |