def finish(self):
        """
        Indicate that all response data has been written to this L{Request}.
        """
        if self._disconnected:
            raise RuntimeError(
                "Request.finish called on a request after its connection was lost; "
                "use Request.notifyFinish to keep track of this.")
        if self.finished:
            warnings.warn("Warning! request.finish called twice.", stacklevel=2)
            return

        if not self.startedWriting:
            # write headers
            self.write(b'')

        if self.chunked:
            # write last chunk and closing CRLF
            self.channel.write(b"0\r\n\r\n")

        # log request
        if (hasattr(self.channel, "factory") and
                self.channel.factory is not None):
            self.channel.factory.log(self)

        self.finished = 1
        if not self.queued:
            self._cleanup()

        Indicate that all response data has been written to this L{Request}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/http.py