Skip to content

Commit 2b64eec

Browse files
authored
🩹 Ensure we exit cleanly in fastcgi or litespeed contexts (#17)
Fixes #15
1 parent 3baaa23 commit 2b64eec

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/Modules/NiceSearchModule.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,28 @@ protected function handleRedirect(): self
5353
! str_contains($request, '&') &&
5454
wp_safe_redirect(get_search_link())
5555
) {
56-
exit;
56+
$this->exit();
5757
}
5858
});
5959

6060
return $this;
6161
}
6262

63+
/**
64+
* Ensure we exit cleanly in fastcgi or litespeed contexts.
65+
* Adapted from https://github.com/symfony/symfony/blob/39c5025839a8610040e8aa190d962169552c41d4/src/Symfony/Component/HttpFoundation/Response.php#L393-L419
66+
*/
67+
protected function exit(): never
68+
{
69+
if (\function_exists('fastcgi_finish_request')) {
70+
fastcgi_finish_request();
71+
} elseif (\function_exists('litespeed_finish_request')) {
72+
litespeed_finish_request();
73+
}
74+
75+
exit;
76+
}
77+
6378
/**
6479
* Handle compatibility with third-party plugins.
6580
*/

0 commit comments

Comments
 (0)