diff --git a/Response.php b/Response.php index a9cea09b3..e6b913f41 100644 --- a/Response.php +++ b/Response.php @@ -311,7 +311,7 @@ public function prepare(Request $request) } // Check if we need to send extra expire info headers - if ('1.0' == $this->getProtocolVersion() && str_contains($headers->get('Cache-Control'), 'no-cache')) { + if ('1.0' == $this->getProtocolVersion() && str_contains($headers->get('Cache-Control', ''), 'no-cache')) { $headers->set('pragma', 'no-cache'); $headers->set('expires', -1); } diff --git a/Tests/ResponseTest.php b/Tests/ResponseTest.php index f26302eef..d4b8812d9 100644 --- a/Tests/ResponseTest.php +++ b/Tests/ResponseTest.php @@ -578,6 +578,12 @@ public function testPrepareSetsPragmaOnHttp10Only() $this->assertEquals('no-cache', $response->headers->get('pragma')); $this->assertEquals('-1', $response->headers->get('expires')); + $response = new Response('foo'); + $response->headers->remove('cache-control'); + $response->prepare($request); + $this->assertFalse($response->headers->has('pragma')); + $this->assertFalse($response->headers->has('expires')); + $request->server->set('SERVER_PROTOCOL', 'HTTP/1.1'); $response = new Response('foo'); $response->prepare($request);