Skip to content

Commit c98b1bb

Browse files
committed
Enhance isJson and isXml methods in Response class to handle null Content-Type headers gracefully
1 parent f9de9c1 commit c98b1bb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Http/Response.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,13 @@ public function header(string $header): string|array|null
496496
*/
497497
public function isJson(): bool
498498
{
499-
return str_contains($this->header('Content-Type'), 'json');
499+
$contentType = $this->header('Content-Type');
500+
501+
if(is_null($contentType)) {
502+
return false;
503+
}
504+
505+
return str_contains($contentType, 'json');
500506
}
501507

502508
/**
@@ -506,7 +512,13 @@ public function isJson(): bool
506512
*/
507513
public function isXml(): bool
508514
{
509-
return str_contains($this->header('Content-Type'), 'xml');
515+
$contentType = $this->header('Content-Type');
516+
517+
if(is_null($contentType)) {
518+
return false;
519+
}
520+
521+
return str_contains($contentType, 'xml');
510522
}
511523

512524
/**

0 commit comments

Comments
 (0)