'Assert, process, and send the HTTP response message-headers.'

def send_headers(self):

    hkeys = [key.lower() for (key, value) in self.outheaders]
    status = int(self.status[:3])
    if (status == 413):
        self.close_connection = True
    elif ('content-length' not in hkeys):
        if ((status < 200) or (status in (204, 205, 304))):
            pass
        elif ((self.response_protocol == 'HTTP/1.1') and (self.environ['REQUEST_METHOD'] != 'HEAD')):
            self.chunked_write = True
            self.outheaders.append(('Transfer-Encoding', 'chunked'))
        else:
            self.close_connection = True
    if ('connection' not in hkeys):
        if (self.response_protocol == 'HTTP/1.1'):
            if self.close_connection:
                self.outheaders.append(('Connection', 'close'))
        elif (not self.close_connection):
            self.outheaders.append(('Connection', 'Keep-Alive'))
    if ((not self.close_connection) and (not self.chunked_read)):
        size = (self.rfile.maxlen - self.rfile.bytes_read)
        if (size > 0):
            self.rfile.read(size)
    if ('date' not in hkeys):
        self.outheaders.append(('Date', rfc822.formatdate()))
    if ('server' not in hkeys):
        self.outheaders.append(('Server', self.environ['SERVER_SOFTWARE']))
    buf = [self.environ['ACTUAL_SERVER_PROTOCOL'], '    ', self.status, '\r\n']
    try:
        buf += [(((k + ':    ') + v) + '\r\n') for (k, v) in self.outheaders]
    except TypeError:
        if (not isinstance(k, str)):
            raise TypeError('WSGI    response    header    key    %r    is    not    a    string.')
        if (not isinstance(v, str)):
            raise TypeError('WSGI    response    header    value    %r    is    not    a    string.')
        else:
            raise
    buf.append('\r\n')
    self.wfile.sendall(''.join(buf))
