@classmethod
def encode_response(cls, response):
    """
        Encodes a Django HTTP response into ASGI http.response message(s).
        """
    response_headers = []
    for header, value in response.items():
        if isinstance(header, str):
            header = header.encode('ascii')
        if isinstance(value, str):
            value = value.encode('latin1')
        response_headers.append((bytes(header), bytes(value)))
    for c in response.cookies.values():
        response_headers.append((b'Set-Cookie', c.output(header='').encode(
            'ascii').strip()))
    yield {'type': 'http.response.start', 'status': response.status_code,
        'headers': response_headers}
    if response.streaming:
        for part in response:
            for chunk, _ in cls.chunk_bytes(part):
                yield {'type': 'http.response.body', 'body': chunk,
                    'more_body': True}
        yield {'type': 'http.response.body'}
    else:
        for chunk, last in cls.chunk_bytes(response.content):
            yield {'type': 'http.response.body', 'body': chunk, 'more_body':
                not last}
