Back to Bolt Python

slack_bolt.adapter.asgi.http_response API documentation

docs/reference/adapter/asgi/http_response.html

1.29.05.1 KB
Original Source

Classes

class AsgiHttpResponse (status: int, headers: Dict[str, Sequence[str]] = {}, body: str = '')#Expand source code

class AsgiHttpResponse:
    __slots__ = ("status", "raw_headers", "body")

    def __init__ (self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = ""):
        self.status: int = status
        self.body: bytes = bytes(body, ENCODING)
        self.raw_headers: List[Tuple[bytes, bytes]] = []
        for key, values in headers.items():
            if key.lower() == "content-length":
                continue
            for v in values:
                self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
        self.raw_headers.append((b"content-length", bytes(str(len(self.body)), ENCODING)))

    def get_response_start(self) -> Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
        return {
            "type": "http.response.start",
            "status": self.status,
            "headers": self.raw_headers,
        }

    def get_response_body(self) -> Dict[str, Union[str, bytes, bool]]:
        return {
            "type": "http.response.body",
            "body": self.body,
            "more_body": False,
        }

Instance variables

var body#Expand source code

class AsgiHttpResponse:
    __slots__ = ("status", "raw_headers", "body")

    def __init__ (self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = ""):
        self.status: int = status
        self.body: bytes = bytes(body, ENCODING)
        self.raw_headers: List[Tuple[bytes, bytes]] = []
        for key, values in headers.items():
            if key.lower() == "content-length":
                continue
            for v in values:
                self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
        self.raw_headers.append((b"content-length", bytes(str(len(self.body)), ENCODING)))

    def get_response_start(self) -> Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
        return {
            "type": "http.response.start",
            "status": self.status,
            "headers": self.raw_headers,
        }

    def get_response_body(self) -> Dict[str, Union[str, bytes, bool]]:
        return {
            "type": "http.response.body",
            "body": self.body,
            "more_body": False,
        }

var raw_headers#Expand source code

class AsgiHttpResponse:
    __slots__ = ("status", "raw_headers", "body")

    def __init__ (self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = ""):
        self.status: int = status
        self.body: bytes = bytes(body, ENCODING)
        self.raw_headers: List[Tuple[bytes, bytes]] = []
        for key, values in headers.items():
            if key.lower() == "content-length":
                continue
            for v in values:
                self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
        self.raw_headers.append((b"content-length", bytes(str(len(self.body)), ENCODING)))

    def get_response_start(self) -> Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
        return {
            "type": "http.response.start",
            "status": self.status,
            "headers": self.raw_headers,
        }

    def get_response_body(self) -> Dict[str, Union[str, bytes, bool]]:
        return {
            "type": "http.response.body",
            "body": self.body,
            "more_body": False,
        }

var status#Expand source code

class AsgiHttpResponse:
    __slots__ = ("status", "raw_headers", "body")

    def __init__ (self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = ""):
        self.status: int = status
        self.body: bytes = bytes(body, ENCODING)
        self.raw_headers: List[Tuple[bytes, bytes]] = []
        for key, values in headers.items():
            if key.lower() == "content-length":
                continue
            for v in values:
                self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
        self.raw_headers.append((b"content-length", bytes(str(len(self.body)), ENCODING)))

    def get_response_start(self) -> Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
        return {
            "type": "http.response.start",
            "status": self.status,
            "headers": self.raw_headers,
        }

    def get_response_body(self) -> Dict[str, Union[str, bytes, bool]]:
        return {
            "type": "http.response.body",
            "body": self.body,
            "more_body": False,
        }

Methods

def get_response_body(self) ‑> Dict[str, str | bytes | bool]#Expand source code

def get_response_body(self) -> Dict[str, Union[str, bytes, bool]]:
    return {
        "type": "http.response.body",
        "body": self.body,
        "more_body": False,
    }

def get_response_start(self) ‑> Dict[str, str | int | Iterable[Tuple[bytes, bytes]]]#Expand source code

def get_response_start(self) -> Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
    return {
        "type": "http.response.start",
        "status": self.status,
        "headers": self.raw_headers,
    }