Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Always replay cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Feb 13, 2018
1 parent 8e9418e commit 1f1f504
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/SymfonyCache/HeaderReplaySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public function preHandle(CacheEvent $event)
$this->replayHeaders($preflightResponse, $request);
}

// Replay Set-Cookie headers (behave like a browser)
$this->replayCookieHeaders($preflightResponse, $request);

// The original request now has our decorated/replayed headers if
// applicable and the kernel can continue normally
}
Expand Down Expand Up @@ -139,9 +142,6 @@ private function replayHeaders(Response $preflightResponse, Request $request)
}
}

// Replay Set-Cookie headers (behave like a browser)
$this->replayCookieHeaders($preflightResponse, $request);

// Force no cache
if ($preflightResponse->headers->has(HeaderReplayListener::FORCE_NO_CACHE_HEADER_NAME)) {
$request->headers->addCacheControlDirective('no-cache');
Expand Down
12 changes: 11 additions & 1 deletion tests/SymfonyCache/HeaderReplaySubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,14 @@ public function testKernelIsCorrectlyCalledWithPreflightAcceptHeader()
* @param Response $response
* @dataProvider noHeadersAddedAndEarlyResponseIfResponseIsNotACorrectPreflightResponse
*/
public function testNoHeadersAddedIfResponseIsNotACorrectPreflightResponse(Response $response)
public function testNoHeadersAddedButCookiesAreReplayedIfResponseIsNotACorrectPreflightResponse(Response $response)
{
$validCookie = new Cookie('i-am-valid', 'foobar', time() + 5000);
$expiredCookie = new Cookie('i-am-expired', 'foobar', 0);

$response->headers->setCookie($validCookie);
$response->headers->setCookie($expiredCookie);

$kernel = $this->createMock(HttpCache::class);
$kernel
->expects($this->once())
Expand Down Expand Up @@ -198,6 +204,10 @@ public function testNoHeadersAddedIfResponseIsNotACorrectPreflightResponse(Respo
// Assert response was not set to event but instead just left for
// the kernel to be handled
$this->assertNull($cacheEvent->getResponse());

// Assert cookies correctly replayed
$this->assertSame('foobar', $request->cookies->get('i-am-valid'));
$this->assertFalse($request->cookies->has('i-am-expired'));
}

public function testReplayHeaders()
Expand Down

0 comments on commit 1f1f504

Please sign in to comment.