8000 bug #40545 [HttpFoundation] Fix isNotModified determination logic (ol… · symfony/http-kernel@47b404f · GitHub
[go: up one dir, main page]

Skip to content

Commit 47b404f

Browse files
committed
bug #40545 [HttpFoundation] Fix isNotModified determination logic (ol0lll)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fix isNotModified determination logic | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #37948 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Use weak comparison for etags; Only do if-modified-since when no if-none-match header is present. See symfony/symfony#37948 (comment) <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry --> Commits ------- 77bd21adfc [HttpFoundation] Fix isNotModified determination logic
2 parents ef2cdd2 + db4eefc commit 47b404f

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": &quo 40BE t;^1.9",
2626
"symfony/polyfill-php80": "^1.16",

0 commit comments

Comments
 (0)
0