parameters: (self, chunk: Optional[Union[str, bytes, dict]] = None)
return_statement: return future
docstring: Finishes this response, ending the HTTP request.
  
          Passing a ``chunk`` to ``finish()`` is equivalent to passing that
          chunk to ``write()`` and then calling ``finish()`` with no arguments.
  
          Returns a `.Future` which may optionally be awaited to track the sending
          of the response to the client. This `.Future` resolves when all the response
          data has been sent, and raises an error if the connection is closed before all
          data can be sent.
  
          .. versionchanged:: 5.1
  
             Now returns a `.Future` instead of ``None``.
docstring_summary: Finishes this response, ending the HTTP request.
docstring_tokens: Finishes this response ending the HTTP request .
function: def finish(self, chunk: Optional[Union[str, bytes, dict]] = None) -> "Future[None]":
          """Finishes this response, ending the HTTP request.
  
          Passing a ``chunk`` to ``finish()`` is equivalent to passing that
          chunk to ``write()`` and then calling ``finish()`` with no arguments.
  
          Returns a `.Future` which may optionally be awaited to track the sending
          of the response to the client. This `.Future` resolves when all the response
          data has been sent, and raises an error if the connection is closed before all
          data can be sent.
  
          .. versionchanged:: 5.1
  
             Now returns a `.Future` instead of ``None``.
          """
          if self._finished:
              raise RuntimeError("finish() called twice")
  
          if chunk is not None:
              self.write(chunk)
  
          # Automatically support ETags and add the Content-Length header if
          # we have not flushed any content yet.
          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 (100 <= self._status_code < 200):
                  assert not self._write_buffer, (
                      "Cannot send body with %s" % self._status_code
                  )
                  self._clear_representation_headers()
              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)
  
          assert self.request.connection is not None
          # Now that the request is finished, clear the callback we
          # set on the HTTPConnection (which would otherwise prevent the
          # garbage collection of the RequestHandler when there
          # are keepalive connections)
          self.request.connection.set_close_callback(None)  # type: ignore
  
          future = self.flush(include_footers=True)
          self.request.connection.finish()
          self._log()
          self._finished = True
          self.on_finish()
          self._break_cycles()
          return future
function_tokens: def finish ( self , chunk : Optional [ Union [ str , bytes , dict ] ] = None ) -> "Future[None]" : if self . _finished : raise RuntimeError ( "finish() called twice" ) if chunk is not None : self . write ( chunk ) # Automatically support ETags and add the Content-Length header if # we have not flushed any content yet. 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 ( 100 <= self . _status_code < 200 ) : assert not self . _write_buffer , ( "Cannot send body with %s" % self . _status_code ) self . _clear_representation_headers ( ) 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 ) assert self . request . connection is not None # Now that the request is finished, clear the callback we # set on the HTTPConnection (which would otherwise prevent the # garbage collection of the RequestHandler when there # are keepalive connections) self . request . connection . set_close_callback ( None ) # type: ignore future = self . flush ( include_footers = True ) self . request . connection . finish ( ) self . _log ( ) self . _finished = True self . on_finish ( ) self . _break_cycles ( ) return future