'Encodes a Django HTTP response into ASGI http.response message(s).'

@classmethod
def encode_response(cls, response):

    response_headers = []
    for (header, value) in response.items():
        if isinstance(header, six.text_type):
            header = header.encode(u'ascii')
        if isinstance(value, six.text_type):
            value = value.encode(u'latin1')
        response_headers.append((six.binary_type(header), six.binary_type(value)))
    for c in response.cookies.values():
        response_headers.append(('Set-Cookie', c.output(header=u'').encode(u'ascii')))
    message = {u'status': response.status_code, u'headers': response_headers}
    if response.streaming:
        for part in response:
            for (chunk, more) in cls.chunk_bytes(part):
                message[u'content'] = chunk
                message[u'more_content'] = True
                (yield message)
                message = {}
        message[u'more_content'] = False
        (yield message)
    else:
        for (chunk, last) in cls.chunk_bytes(response.content):
            message[u'content'] = chunk
            message[u'more_content'] = (not last)
            (yield message)
            message = {}
