'Send `data` to the server in chunk-encoded form.
Check the connection before writing and reconnect
if disconnected and if the response status code is in `reconnect_on`.
The response may either be an HTTPResponse object or an empty string.'

def write(self, data, reconnect_on=('', 200)):

    if (not self._isconnected()):
        response = self._getresponse()
        if (((response == '') and ('' in reconnect_on)) or (response and isinstance(response, http_client.HTTPResponse) and (response.status in reconnect_on))):
            self._reconnect()
        elif (response and isinstance(response, http_client.HTTPResponse)):
            raise Exception('Server    responded    with    status    code:    {status_code}\nand    message:    {msg}.'.format(status_code=response.status, msg=response.read()))
        elif (response == ''):
            raise Exception('Attempted    to    write    but    socket    was    not    connected.')
    try:
        msg = data
        msglen = format(len(msg), 'x')
        self._conn.sock.setblocking(1)
        self._conn.send('{msglen}\r\n{msg}\r\n'.format(msglen=msglen, msg=msg).encode('utf-8'))
        self._conn.sock.setblocking(0)
    except http_client.socket.error:
        self._reconnect()
        self.write(data)
