Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6db566d

Browse files
committed
17139: do not send default cache header for 301 redirects
1 parent 83ebf97 commit 6db566d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,11 @@ public function prepare(Request $request)
310310
$this->headers->set('expires', -1);
311311
}
312312

313+
// Don't send default cache header for 301 redirects
314+
if (301 == $this->statusCode && !array_key_exists('cache-control', $this->headers)) {
315+
$this->headers->remove('cache-control');
316+
}
317+
313318
$this->ensureIEOverSSLCompatibility($request);
314319

315320
return $this;

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,14 @@ public function testPrepareRemovesContentLength()
544544
$this->assertFalse($response->headers->has('Content-Length'));
545545
}
546546

547+
public function testPrepareRemovesDefaultCacheHeaderForPermanentRedirect()
548+
{
549+
$response = new Response('foo', 301);
550+
$request = Request::create('/');
551+
$response->prepare($request);
552+
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
553+
}
554+
547555
public function testPrepareSetsPragmaOnHttp10Only()
548556
{
549557
$request = Request::create('/', 'GET');

0 commit comments

Comments
 (0)