gitea.utils.response
response
Utility functions for processing HTTP responses.
Functions:
gitea.utils.response.process_response
Process a synchronous HTTP response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The HTTP response object. |
required |
default
|
T | None
|
The default value to return if parsing fails. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Any, int]
|
A tuple containing the response data and status code. |
Source code in src/gitea/utils/response.py
gitea.utils.response.process_async_response
async
Process an asynchronous HTTP response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
ClientResponse
|
The asynchronous HTTP response object. |
required |
default
|
T | None
|
The default value to return if parsing fails. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Any, int]
|
A tuple containing the response data and status code. |
Source code in src/gitea/utils/response.py
gitea.utils.response.process_text_response
Process a synchronous HTTP response whose body is text rather than JSON.
A few endpoints answer with a file rather than with a document - the logs of an Actions job are the log itself - so there is nothing to parse and nothing to fall back to when parsing fails.
The body is decoded as UTF-8 rather than through response.text, which
guesses the encoding when the response declares none: a log blob served as
application/octet-stream would be decoded by that guess, and the same
bytes would then reach a caller differently depending on what the guess
was. Gitea writes these as UTF-8, and the asynchronous path decodes them the
same way, so both clients hand back the same text. A byte that is not valid
UTF-8 is replaced rather than raising, since a log is worth reading even
where one line of it is malformed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The HTTP response object. |
required |
default
|
str
|
The value to return when the response carries no body. |
''
|
Returns:
| Type | Description |
|---|---|
tuple[str, int]
|
A tuple containing the response text and status code. |
Source code in src/gitea/utils/response.py
gitea.utils.response.process_async_text_response
async
Process an asynchronous HTTP response whose body is text rather than JSON.
Decoded as process_text_response decodes it, so a caller reading the logs
of a job gets the same text from either client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
ClientResponse
|
The asynchronous HTTP response object. |
required |
default
|
str
|
The value to return when the response carries no body. |
''
|
Returns:
| Type | Description |
|---|---|
tuple[str, int]
|
A tuple containing the response text and status code. |
Source code in src/gitea/utils/response.py
gitea.utils.response.process_binary_response
Process a synchronous HTTP response whose body is a file rather than a document.
An Actions artifact is a zip archive, so there is nothing to parse and
nothing to decode: handing back the bytes is the whole of it. Decoding them
as text - as the log endpoints are decoded - would replace every byte that is
not valid UTF-8 and produce an archive that no longer opens, which is why
this exists alongside process_text_response rather than reusing it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Response
|
The HTTP response object. |
required |
default
|
bytes
|
The value to return when the response carries no body. |
b''
|
Returns:
| Type | Description |
|---|---|
tuple[bytes, int]
|
A tuple containing the response body and status code. |
Source code in src/gitea/utils/response.py
gitea.utils.response.process_async_binary_response
async
process_async_binary_response(
response: ClientResponse, default: bytes = b""
) -> tuple[bytes, int]
Process an asynchronous HTTP response whose body is a file rather than a document.
Handed back as process_binary_response hands it back, so an artifact
downloaded through either client is the same archive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
ClientResponse
|
The asynchronous HTTP response object. |
required |
default
|
bytes
|
The value to return when the response carries no body. |
b''
|
Returns:
| Type | Description |
|---|---|
tuple[bytes, int]
|
A tuple containing the response body and status code. |