MCPcopy
hub / github.com/tornadoweb/tornado / finish

Method finish

tornado/http1connection.py:507–537  ·  view source on GitHub ↗

Implements `.HTTPConnection.finish`.

(self)

Source from the content-addressed store, hash-verified

505 return future
506
507 def finish(self) -> None:
508 """Implements `.HTTPConnection.finish`."""
509 if (
510 self._expected_content_remaining is not None
511 and self._expected_content_remaining != 0
512 and not self.stream.closed()
513 ):
514 self.stream.close()
515 raise httputil.HTTPOutputError(
516 "Tried to write %d bytes less than Content-Length"
517 % self._expected_content_remaining
518 )
519 if self._chunking_output:
520 if not self.stream.closed():
521 self._pending_write = self.stream.write(b"0\r\n\r\n")
522 self._pending_write.add_done_callback(self._on_write_complete)
523 self._write_finished = True
524 # If the app finished the request while we're still reading,
525 # divert any remaining data away from the delegate and
526 # close the connection when we're done sending our response.
527 # Closing the connection is the only way to avoid reading the
528 # whole input body.
529 if not self._read_finished:
530 self._disconnect_on_finish = True
531 # No more data is coming, so instruct TCP to send any remaining
532 # data immediately instead of waiting for a full packet or ack.
533 self.stream.set_nodelay(True)
534 if self._pending_write is None:
535 self._finish_request(None)
536 else:
537 future_add_done_callback(self._pending_write, self._finish_request)
538
539 def _on_write_complete(self, future: "Future[None]") -> None:
540 exc = future.exception()

Callers 2

_read_messageMethod · 0.45
finishMethod · 0.45

Calls 6

_finish_requestMethod · 0.95
future_add_done_callbackFunction · 0.90
closedMethod · 0.80
closeMethod · 0.45
writeMethod · 0.45
set_nodelayMethod · 0.45

Tested by

no test coverage detected