diff --git a/lib/private/AppFramework/App.php b/lib/private/AppFramework/App.php index 7bf32852209..1a82fe58345 100644 --- a/lib/private/AppFramework/App.php +++ b/lib/private/AppFramework/App.php @@ -213,5 +213,10 @@ class App { $io->setOutput($output); } } + + if ($response->getFlushEarly()) { + ob_flush(); + flush(); + } } } diff --git a/lib/public/AppFramework/Http/Response.php b/lib/public/AppFramework/Http/Response.php index 6edd32a1f8b..b602776567b 100644 --- a/lib/public/AppFramework/Http/Response.php +++ b/lib/public/AppFramework/Http/Response.php @@ -66,6 +66,7 @@ class Response { /** @var bool */ private $throttled = false; + private bool $flushEarly = true; /** @var array */ private $throttleMetadata = []; @@ -412,4 +413,25 @@ class Response { public function isThrottled() { return $this->throttled; } + + /** + * Request the response should be flushed to the connected client immediately + * + * @since 34.0.0 + */ + public function setFlushEarly(bool $flushEarly): void { + $this->flushEarly = $flushEarly; + } + + /** + * Whether the response should be flushed to the connected client immediately + * + * If not, the response will wait for async actions, e.g. HTTP requests from + * IClientService, to be finished before returning. + * + * @since 34.0.0 + */ + public function getFlushEarly(): bool { + return $this->flushEarly; + } }