Skip to content

Commit a555dad

Browse files
[SS-2024-002] Detect if debugging in HTML context (#11553)
Co-authored-by: Steve Boyd <emteknetnz@gmail.com>
1 parent cd1d5de commit a555dad

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Dev/Debug.php

+8-4
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,20 @@ protected static function supportsHTML(HTTPRequest $request = null)
164164
if (Director::is_cli()) {
165165
return false;
166166
}
167+
$accepted = [];
167168

168169
// Get current request if registered
169170
if (!$request && Injector::inst()->has(HTTPRequest::class)) {
170171
$request = Injector::inst()->get(HTTPRequest::class);
171172
}
172-
if (!$request) {
173-
return false;
173+
if ($request) {
174+
$accepted = $request->getAcceptMimetypes(false);
175+
} elseif (isset($_SERVER['HTTP_ACCEPT'])) {
176+
// If there's no request object available, fallback to global $_SERVER
177+
// This can happen in some circumstances when a PHP error is triggered
178+
// during a regular HTTP request
179+
$accepted = preg_split('#\s*,\s*#', $_SERVER['HTTP_ACCEPT']);
174180
}
175-
// Request must include text/html
176-
$accepted = $request->getAcceptMimetypes(false);
177181

178182
// Explicit opt in
179183
if (in_array('text/html', $accepted ?? [])) {

0 commit comments

Comments
 (0)