Module astrapy.utils.request_tools

Functions

def log_httpx_request(http_method: str,
full_url: str,
request_params: dict[str, Any] | None,
redacted_request_headers: dict[str, str],
encoded_payload: str | None,
timeout_context: _TimeoutContext,
caller_function_name: str | None) ‑> None
Expand source code
def log_httpx_request(
    http_method: str,
    full_url: str,
    request_params: dict[str, Any] | None,
    redacted_request_headers: dict[str, str],
    encoded_payload: str | None,
    timeout_context: _TimeoutContext,
    caller_function_name: str | None,
) -> None:
    """
    Log the details of an HTTP request for debugging purposes.

    Args:
        http_method: the HTTP verb of the request (e.g. "POST").
        full_url: the URL of the request (e.g. "https://domain.com/full/path").
        request_params: parameters of the request.
        redacted_request_headers: caution, as these will be logged as they are.
        encoded_payload: the payload (in bytes) sent with the request, if any.
        timeout_ms: the timeout in milliseconds, if any is set.
    """
    logger.debug(f"Request URL: {http_method} {full_url}")
    if request_params:
        logger.debug(f"Request params: '{request_params}'")
    if redacted_request_headers:
        logger.debug(f"Request headers: '{redacted_request_headers}'")
    if encoded_payload is not None:
        logger.debug(f"Request payload: '{encoded_payload}'")
    if timeout_context:
        logger.debug(
            f"Timeout (ms): for request {timeout_context.request_ms or '(unset)'} ms"
            f", overall operation {timeout_context.nominal_ms or '(unset)'} ms"
        )
    if caller_function_name:
        logger.debug(f"Request invoked by function: '{caller_function_name}'")

Log the details of an HTTP request for debugging purposes.

Args

http_method
the HTTP verb of the request (e.g. "POST").
full_url
the URL of the request (e.g. "https://domain.com/full/path").
request_params
parameters of the request.
redacted_request_headers
caution, as these will be logged as they are.
encoded_payload
the payload (in bytes) sent with the request, if any.
timeout_ms
the timeout in milliseconds, if any is set.
def log_httpx_response(response: httpx.Response) ‑> None
Expand source code
def log_httpx_response(response: httpx.Response) -> None:
    """
    Log the details of an httpx.Response.

    Args:
        response: the httpx.Response object to log.
    """
    logger.debug(f"Response status code: {response.status_code}")
    logger.debug(f"Response headers: '{response.headers}'")
    logger.debug(f"Response text: '{response.text}'")

Log the details of an httpx.Response.

Args

response
the httpx.Response object to log.
def to_httpx_timeout(timeout_context: _TimeoutContext) ‑> httpx.Timeout | None
Expand source code
def to_httpx_timeout(timeout_context: _TimeoutContext) -> httpx.Timeout | None:
    if timeout_context.request_ms is None or timeout_context.request_ms == 0:
        return None
    else:
        return httpx.Timeout(timeout_context.request_ms / 1000)

Classes

class HttpMethod
Expand source code
class HttpMethod:
    GET = "GET"
    POST = "POST"
    PUT = "PUT"
    PATCH = "PATCH"
    DELETE = "DELETE"

Class variables

var DELETE

The type of the None singleton.

var GET

The type of the None singleton.

var PATCH

The type of the None singleton.

var POST

The type of the None singleton.

var PUT

The type of the None singleton.