Skip to content

Response

faststream.broker.response.Response #

Response(body, *, headers=None, correlation_id=None)

Initialize a handler.

Source code in faststream/broker/response.py
def __init__(
    self,
    body: "Any",
    *,
    headers: Optional["AnyDict"] = None,
    correlation_id: Optional[str] = None,
) -> None:
    """Initialize a handler."""
    self.body = body
    self.headers = headers or {}
    self.correlation_id = correlation_id

body instance-attribute #

body = body

headers instance-attribute #

headers = headers or {}

correlation_id instance-attribute #

correlation_id = correlation_id

add_headers #

add_headers(extra_headers, *, override=True)
Source code in faststream/broker/response.py
def add_headers(
    self,
    extra_headers: "AnyDict",
    *,
    override: bool = True,
) -> None:
    if override:
        self.headers = {**self.headers, **extra_headers}
    else:
        self.headers = {**extra_headers, **self.headers}

as_publish_kwargs #

as_publish_kwargs()
Source code in faststream/broker/response.py
def as_publish_kwargs(self) -> "AnyDict":
    publish_options = {
        "headers": self.headers,
        "correlation_id": self.correlation_id,
    }
    return publish_options