import json


def create_response(response):
    """
    A funtion that creates a response message with appropriate headers.
    return: status, headers, response
    """
    # Convert dictionary to json
    res = json.dumps(response)

    # Set Response headers
    response_headers = {
        'Content-Type': 'application/json; encoding=utf8',
        'Content-Length': len(res.encode(encoding="utf-8")),
        'Connection': 'close',
    }

    # Format resposne  headers
    response_headers_raw = ''.join('%s: %s\n' % (k, v) for k, v in response_headers.items())

    # Set HTTP version, status code and status
    response_proto = 'HTTP/1.1'
    response_status = '200'
    response_status_text = 'OK' # this can be random

    # Format data
    r = '%s %s %s' % (response_proto, response_status, response_status_text)
    
    return r, response_headers_raw, res