Skip to content

Commit 86fbc60

Browse files
committed
🎨 Send response headers inside the send_headers hook
🎨 Change the `shutdown` hook to `Response::sendContent` and implement the `Response::send` flush logic
1 parent f0200ac commit 86fbc60

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/Roots/Acorn/Application/Concerns/Bootable.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,22 +234,21 @@ protected function registerRequestHandler(
234234

235235
$response = $kernel->handle($request);
236236

237-
add_action('send_headers', function () use ($response) {
238-
foreach ($response->headers->getCookies() as $cookie) {
239-
setcookie(
240-
$cookie->getName(),
241-
$cookie->getValue(),
242-
$cookie->getExpiresTime(),
243-
$cookie->getPath(),
244-
$cookie->getDomain(),
245-
$cookie->isSecure(),
246-
$cookie->isHttpOnly()
247-
);
248-
}
249-
}, 100);
237+
$response->headers->remove('cache-control');
238+
239+
add_action('send_headers', fn () => $response->sendHeaders(), 100);
250240

251241
add_action('shutdown', function () use ($kernel, $request, $response) {
252-
$response->send();
242+
$response->sendContent();
243+
244+
if (function_exists('fastcgi_finish_request')) {
245+
fastcgi_finish_request();
246+
} elseif (function_exists('litespeed_finish_request')) {
247+
litespeed_finish_request();
248+
} elseif (! in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
249+
Response::closeOutputBuffers(0, true);
250+
flush();
251+
}
253252

254253
$kernel->terminate($request, $response);
255254

0 commit comments

Comments
 (0)