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

Method flush

tornado/web.py:1220–1268  ·  view source on GitHub ↗

Flushes the current output buffer to the network. .. versionchanged:: 4.0 Now returns a `.Future` if no callback is given. .. versionchanged:: 6.0 The ``callback`` argument was removed.

(self, include_footers: bool = False)

Source from the content-addressed store, hash-verified

1218 return template.Loader(template_path, **kwargs)
1219
1220 def flush(self, include_footers: bool = False) -> "Future[None]":
1221 """Flushes the current output buffer to the network.
1222
1223 .. versionchanged:: 4.0
1224 Now returns a `.Future` if no callback is given.
1225
1226 .. versionchanged:: 6.0
1227
1228 The ``callback`` argument was removed.
1229 """
1230 assert self.request.connection is not None
1231 chunk = b"".join(self._write_buffer)
1232 self._write_buffer = []
1233 if not self._headers_written:
1234 self._headers_written = True
1235 for transform in self._transforms:
1236 assert chunk is not None
1237 (
1238 self._status_code,
1239 self._headers,
1240 chunk,
1241 ) = transform.transform_first_chunk(
1242 self._status_code, self._headers, chunk, include_footers
1243 )
1244 # Ignore the chunk and only write the headers for HEAD requests
1245 if self.request.method == "HEAD":
1246 chunk = b""
1247
1248 # Finalize the cookie headers (which have been stored in a side
1249 # object so an outgoing cookie could be overwritten before it
1250 # is sent).
1251 if hasattr(self, "_new_cookie"):
1252 for cookie in self._new_cookie.values():
1253 self.add_header("Set-Cookie", cookie.OutputString(None))
1254
1255 start_line = httputil.ResponseStartLine("", self._status_code, self._reason)
1256 return self.request.connection.write_headers(
1257 start_line, self._headers, chunk
1258 )
1259 else:
1260 for transform in self._transforms:
1261 chunk = transform.transform_chunk(chunk, include_footers)
1262 # Ignore the chunk and only write the headers for HEAD requests
1263 if self.request.method != "HEAD":
1264 return self.request.connection.write(chunk)
1265 else:
1266 future = Future() # type: Future[None]
1267 future.set_result(None)
1268 return future
1269
1270 def finish(self, chunk: Optional[Union[str, bytes, dict]] = None) -> "Future[None]":
1271 """Finishes this response, ending the HTTP request.

Callers 5

finishMethod · 0.95
getMethod · 0.45
transform_chunkMethod · 0.45
finishMethod · 0.45
getMethod · 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