Module slack_bolt.adapter.asgi.http_response

Expand source code
from typing import Iterable, Sequence, Tuple, Dict, Union, List

from .utils import ENCODING


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

    def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = ""):
        self.status: int = status
        self.raw_headers: List[Tuple[bytes, bytes]] = [
            (bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
        ]
        self.raw_headers.append((b"content-length", bytes(str(len(body)), ENCODING)))
        self.body: bytes = bytes(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,
        }

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.raw_headers: List[Tuple[bytes, bytes]] = [
            (bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
        ]
        self.raw_headers.append((b"content-length", bytes(str(len(body)), ENCODING)))
        self.body: bytes = bytes(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

Return an attribute of instance, which is of type owner.

var raw_headers

Return an attribute of instance, which is of type owner.

var status

Return an attribute of instance, which is of type owner.

Methods

def get_response_body(self) ‑> Dict[str, Union[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, Union[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,
    }