'Implements `.HTTPConnection.write`.
For backwards compatibility it is allowed but deprecated to
skip `write_headers` and instead call `write()` with a
pre-encoded header block.'

def write(self, chunk, callback=None):

    future = None
    if self.stream.closed():
        future = self._write_future = Future()
        self._write_future.set_exception(iostream.StreamClosedError())
        self._write_future.exception()
    else:
        if (callback is not None):
            self._write_callback = stack_context.wrap(callback)
        else:
            future = self._write_future = Future()
        self._pending_write = self.stream.write(self._format_chunk(chunk))
        self._pending_write.add_done_callback(self._on_write_complete)
    return future
