MCPcopy
hub / github.com/opendevops-cn/opendevops / flush

Method flush

scripts/tornado_source_code/tornado/web.py:1051–1101  ·  view source on GitHub ↗

Flushes the current output buffer to the network. The ``callback`` argument, if given, can be used for flow control: it will be run when all flushed data has been written to the socket. Note that only one flush callback can be outstanding at a time; if another flush

(self, include_footers: bool = False)

Source from the content-addressed store, hash-verified

1049 return template.Loader(template_path, **kwargs)
1050
1051 def flush(self, include_footers: bool = False) -> "Future[None]":
1052 """Flushes the current output buffer to the network.
1053
1054 The ``callback`` argument, if given, can be used for flow control:
1055 it will be run when all flushed data has been written to the socket.
1056 Note that only one flush callback can be outstanding at a time;
1057 if another flush occurs before the previous flush's callback
1058 has been run, the previous callback will be discarded.
1059
1060 .. versionchanged:: 4.0
1061 Now returns a `.Future` if no callback is given.
1062
1063 .. versionchanged:: 6.0
1064
1065 The ``callback`` argument was removed.
1066 """
1067 assert self.request.connection is not None
1068 chunk = b"".join(self._write_buffer)
1069 self._write_buffer = []
1070 if not self._headers_written:
1071 self._headers_written = True
1072 for transform in self._transforms:
1073 assert chunk is not None
1074 self._status_code, self._headers, chunk = transform.transform_first_chunk(
1075 self._status_code, self._headers, chunk, include_footers
1076 )
1077 # Ignore the chunk and only write the headers for HEAD requests
1078 if self.request.method == "HEAD":
1079 chunk = b""
1080
1081 # Finalize the cookie headers (which have been stored in a side
1082 # object so an outgoing cookie could be overwritten before it
1083 # is sent).
1084 if hasattr(self, "_new_cookie"):
1085 for cookie in self._new_cookie.values():
1086 self.add_header("Set-Cookie", cookie.OutputString(None))
1087
1088 start_line = httputil.ResponseStartLine("", self._status_code, self._reason)
1089 return self.request.connection.write_headers(
1090 start_line, self._headers, chunk
1091 )
1092 else:
1093 for transform in self._transforms:
1094 chunk = transform.transform_chunk(chunk, include_footers)
1095 # Ignore the chunk and only write the headers for HEAD requests
1096 if self.request.method != "HEAD":
1097 return self.request.connection.write(chunk)
1098 else:
1099 future = Future() # type: Future[None]
1100 future.set_result(None)
1101 return future
1102
1103 def finish(self, chunk: Union[str, bytes, dict] = None) -> "Future[None]":
1104 """Finishes this response, ending the HTTP request.

Callers 4

finishMethod · 0.95
getMethod · 0.45
transform_chunkMethod · 0.45
finishMethod · 0.45

Calls 6

add_headerMethod · 0.95
joinMethod · 0.80
transform_first_chunkMethod · 0.45
write_headersMethod · 0.45
transform_chunkMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected