'Finishes this response, ending the HTTP request.'

def finish(self, chunk=None):

    if self._finished:
        raise RuntimeError('finish()    called    twice')
    if (chunk is not None):
        self.write(chunk)
    if (not self._headers_written):
        if ((self._status_code == 200) and (self.request.method in ('GET', 'HEAD')) and ('Etag' not in self._headers)):
            self.set_etag_header()
            if self.check_etag_header():
                self._write_buffer = []
                self.set_status(304)
        if ((self._status_code in (204, 304)) or ((self._status_code >= 100) and (self._status_code < 200))):
            assert (not self._write_buffer), ('Cannot    send    body    with    %s' % self._status_code)
            self._clear_headers_for_304()
        elif ('Content-Length' not in self._headers):
            content_length = sum((len(part) for part in self._write_buffer))
            self.set_header('Content-Length', content_length)
    if hasattr(self.request, 'connection'):
        self.request.connection.set_close_callback(None)
    self.flush(include_footers=True)
    self.request.finish()
    self._log()
    self._finished = True
    self.on_finish()
    self._break_cycles()
