bug #19290 [HttpKernel] fixed internal subrequests having an if-modified-since-header (MalteWunsch)

This PR was squashed before being merged into the 2.7 branch (closes #19290).

Discussion
----------

[HttpKernel] fixed internal subrequests having an if-modified-since-header

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

As the InlineFragmentRenderer has no access to a cached copy of a subrequest's target and hence couldn't handle a response with a HTTP status code of 304 (not modified), it makes no sense to send an if-not-modified-since header.

Commits
-------

e90038c [HttpKernel] fixed internal subrequests having an if-modified-since-header
This commit is contained in:
Fabien Potencier 2016-07-08 12:11:06 +02:00
commit b795cfadcb
2 changed files with 15 additions and 0 deletions

View File

@ -129,6 +129,8 @@ class InlineFragmentRenderer extends RoutableFragmentRenderer
}
$server['REMOTE_ADDR'] = '127.0.0.1';
unset($server['HTTP_IF_MODIFIED_SINCE']);
unset($server['HTTP_IF_NONE_MATCH']);
$subRequest = Request::create($uri, 'get', array(), $cookies, array(), $server);
if ($request->headers->has('Surrogate-Capability')) {

View File

@ -197,6 +197,19 @@ class InlineFragmentRendererTest extends \PHPUnit_Framework_TestCase
Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
}
public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest()
{
$expectedSubRequest = Request::create('/');
if (Request::getTrustedHeaderName(Request::HEADER_CLIENT_IP)) {
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
}
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*'));
$strategy->render('/', $request);
}
}
class Bar