Skip to content

Commit

Permalink
17139: do not send default cache header for 301 redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
e-moe committed Mar 18, 2016
1 parent 00ccd96 commit be9633c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function __construct($url, $status = 302, $headers = array())
if (!$this->isRedirect()) {
throw new \InvalidArgumentException(sprintf('The HTTP status code is not a redirect ("%s" given).', $status));
}

if (301 == $status && !array_key_exists('cache-control', $headers)) {
$this->headers->remove('cache-control');
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions Tests/RedirectResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ public function testCreate()
$this->assertInstanceOf('Symfony\Component\HttpFoundation\RedirectResponse', $response);
$this->assertEquals(301, $response->getStatusCode());
}

public function testCacheHeaders()
{
$response = new RedirectResponse('foo.bar', 301);
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));

$response = new RedirectResponse('foo.bar', 301, array('cache-control' => 'max-age=86400'));
$this->assertFalse($response->headers->hasCacheControlDirective('no-cache'));
$this->assertTrue($response->headers->hasCacheControlDirective('max-age'));

$response = new RedirectResponse('foo.bar', 302);
$this->assertTrue($response->headers->hasCacheControlDirective('no-cache'));
}
}

0 comments on commit be9633c

Please sign in to comment.