8000 [HttpFoundation] Fix isNotModified determination logic · symfony/http-kernel@db4eefc · GitHub
[go: up one dir, main page]

Skip to content

Commit db4eefc

Browse files
ol0lllfabpot
authored andcommitted
[HttpFoundation] Fix isNotModified determination logic
1 parent 46e66e8 commit db4eefc

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

HttpCache/HttpCache.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
/*
413
* This file is part of the Symfony package.
514
*
@@ -382,7 +391,7 @@ protected function validate(Request $request, Response $entry, $catch = false)
382391

383392
// add our cached last-modified validator
384393
if ($entry->headers->has('Last-Modified')) {
385-
$subRequest->headers->set('if_modified_since', $entry->headers->get('Last-Modified'));
394+
$subRequest->headers->set('If-Modified-Since', $entry->headers->get('Last-Modified'));
386395
}
387396

388397
// Add our cached etag validator to the environment.
@@ -391,7 +400,7 @@ protected function validate(Request $request, Response $entry, $catch = false)
391400
$cachedEtags = $entry->getEtag() ? [$entry->getEtag()] : [];
392401
$requestEtags = $request->getETags();
393402
if ($etags = array_unique(array_merge($cachedEtags, $requestEtags))) {
394-
$subRequest->headers->set('if_none_match', implode(', ', $etags));
403+
$subRequest->headers->set('If-None-Match', implode(', ', $etags));
395404
}
396405

397406
$response = $this->forward($subRequest, $catch, $entry);
@@ -444,8 +453,8 @@ protected function fetch(Request $request, $catch = false)
444453
}
445454

446455
// avoid that the backend sends no content
447-
$subRequest->headers->remove('if_modified_since');
448-
$subRequest->headers->remove('if_none_match');
456+
$subRequest->headers->remove('If-Modified-Since');
457+
$subRequest->headers->remove('If-None-Match');
449458

450459
$response = $this->forward($subRequest, $catch);
451460

Tests/HttpCache/HttpCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testRespondsWith304WhenIfNoneMatchMatchesETag()
156156
$this->assertTraceContains('store');
157157
}
158158

159-
public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch()
159+
public function testRespondsWith304WhenIfNoneMatchAndIfModifiedSinceBothMatch()
160160
{
161161
$time = \DateTime::createFromFormat('U', time());
162162

@@ -172,7 +172,7 @@ public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch(
172172
$t = \DateTime::createFromFormat('U', time() - 3600);
173173
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '12345', 'HTTP_IF_MODIFIED_SINCE' => $t->format(\DATE_RFC2822)]);
174174
$this->assertHttpKernelIsCalled();
175-
$this->assertEquals(200, $this->response->getStatusCode());
175+
$this->assertEquals(304, $this->response->getStatusCode());
176176

177177
// only Last-Modified matches
178178
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '1234', 'HTTP_IF_MODIFIED_SINCE' => $time->format(\DATE_RFC2822)]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/error-handler": "^4.4",
2121
"symfony/event-dispatcher": "^4.4",
2222
"symfony/http-client-contracts": "^1.1|^2",
23-
"symfony/http-foundation": "^4.4|^5.0",
23+
"symfony/http-foundation": "^4.4.24|^5.2.9",
2424
"symfony/polyfill-ctype": "^1.8",
2525
"symfony/polyfill-php73": "^1.9",
2626
"symfony/polyfill-php80": "^1.15",

0 commit comments

Comments
 (0)
0