Skip to content

Commit

Permalink
[8.x] Make accept header comparison case-insensitive (#39413)
Browse files Browse the repository at this point in the history
* Make accept header comparison case-insensitive

* Update comment and ref link

* Update InteractsWithContentTypes.php

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
kunalray1993 and taylorotwell authored Oct 29, 2021
1 parent 1fc9c30 commit 32f9313
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Concerns/InteractsWithContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function wantsJson()
{
$acceptable = $this->getAcceptableContentTypes();

return isset($acceptable[0]) && Str::contains($acceptable[0], ['/json', '+json']);
return isset($acceptable[0]) && Str::contains(strtolower($acceptable[0]), ['/json', '+json']);
}

/**
Expand All @@ -60,6 +60,10 @@ public function accepts($contentTypes)
}

foreach ($types as $type) {
$accept = strtolower($accept);

$type = strtolower($type);

if ($this->matchesType($accept, $type) || $accept === strtok($type, '/').'/*') {
return true;
}
Expand Down Expand Up @@ -93,6 +97,10 @@ public function prefers($contentTypes)
$type = $mimeType;
}

$accept = strtolower($accept);

$type = strtolower($type);

if ($this->matchesType($type, $accept) || $accept === strtok($type, '/').'/*') {
return $contentType;
}
Expand Down

0 comments on commit 32f9313

Please sign in to comment.