diff --git a/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php b/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php index 9ddb3c3b5cb2..8037bd55ff6f 100644 --- a/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php +++ b/src/Illuminate/Http/Concerns/InteractsWithContentTypes.php @@ -53,6 +53,10 @@ public function wantsAnyContentType() { $acceptable = $this->getAcceptableContentTypes(); + if (count($acceptable) === 0) { + return true; + } + return isset($acceptable[0]) && ($acceptable[0] === '*/*' || $acceptable[0] === '*'); } diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index ec21b937ae35..7642c2754322 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -594,6 +594,9 @@ public function testExpectsJson() $request = Request::create('/', 'GET', [], [], [], ['HTTP_ACCEPT' => '*/*', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); $this->assertTrue($request->expectsJson()); + $request = Request::create('/', 'GET', [], [], [], ['HTTP_ACCEPT' => null, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest']); + $this->assertTrue($request->expectsJson()); + $request = Request::create('/', 'GET', [], [], [], ['HTTP_ACCEPT' => '*/*', 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest', 'HTTP_X_PJAX' => 'true']); $this->assertFalse($request->expectsJson());