Laravel version update
Laravel version update
This commit is contained in:
@@ -11,9 +11,11 @@
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\HttpCache;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Esi;
|
||||
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
|
||||
use Symfony\Component\HttpKernel\HttpCache\Store;
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
/**
|
||||
@@ -213,7 +215,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
if ($request->cookies->has('authenticated')) {
|
||||
$response->headers->set('Cache-Control', 'private, no-store');
|
||||
$response->setETag('"private tag"');
|
||||
if (in_array('"private tag"', $etags)) {
|
||||
if (\in_array('"private tag"', $etags)) {
|
||||
$response->setStatusCode(304);
|
||||
} else {
|
||||
$response->setStatusCode(200);
|
||||
@@ -223,7 +225,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
} else {
|
||||
$response->headers->set('Cache-Control', 'public');
|
||||
$response->setETag('"public tag"');
|
||||
if (in_array('"public tag"', $etags)) {
|
||||
if (\in_array('"public tag"', $etags)) {
|
||||
$response->setStatusCode(304);
|
||||
} else {
|
||||
$response->setStatusCode(200);
|
||||
@@ -530,8 +532,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTrue(strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')) < 2);
|
||||
$this->assertTrue($this->response->headers->get('Age') > 0);
|
||||
$this->assertLessThan(2, strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')));
|
||||
$this->assertGreaterThan(0, $this->response->headers->get('Age'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTraceContains('fresh');
|
||||
$this->assertTraceNotContains('store');
|
||||
@@ -554,14 +556,54 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTrue(strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')) < 2);
|
||||
$this->assertTrue($this->response->headers->get('Age') > 0);
|
||||
$this->assertLessThan(2, strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')));
|
||||
$this->assertGreaterThan(0, $this->response->headers->get('Age'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTraceContains('fresh');
|
||||
$this->assertTraceNotContains('store');
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
}
|
||||
|
||||
public function testDegradationWhenCacheLocked()
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
$this->markTestSkipped('Skips on windows to avoid permissions issues.');
|
||||
}
|
||||
|
||||
$this->cacheConfig['stale_while_revalidate'] = 10;
|
||||
|
||||
// The prescence of Last-Modified makes this cacheable (because Response::isValidateable() then).
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=5', 'Last-Modified' => 'some while ago'), 'Old response');
|
||||
$this->request('GET', '/'); // warm the cache
|
||||
|
||||
// Now, lock the cache
|
||||
$concurrentRequest = Request::create('/', 'GET');
|
||||
$this->store->lock($concurrentRequest);
|
||||
|
||||
/*
|
||||
* After 10s, the cached response has become stale. Yet, we're still within the "stale_while_revalidate"
|
||||
* timeout so we may serve the stale response.
|
||||
*/
|
||||
sleep(10);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTraceContains('stale-while-revalidate');
|
||||
$this->assertEquals('Old response', $this->response->getContent());
|
||||
|
||||
/*
|
||||
* Another 10s later, stale_while_revalidate is over. Resort to serving the old response, but
|
||||
* do so with a "server unavailable" message.
|
||||
*/
|
||||
sleep(10);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(503, $this->response->getStatusCode());
|
||||
$this->assertEquals('Old response', $this->response->getContent());
|
||||
}
|
||||
|
||||
public function testHitsCachedResponseWithSMaxAgeDirective()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() - 5);
|
||||
@@ -578,8 +620,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTrue(strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')) < 2);
|
||||
$this->assertTrue($this->response->headers->get('Age') > 0);
|
||||
$this->assertLessThan(2, strtotime($this->responses[0]->headers->get('Date')) - strtotime($this->response->headers->get('Date')));
|
||||
$this->assertGreaterThan(0, $this->response->headers->get('Age'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTraceContains('fresh');
|
||||
$this->assertTraceNotContains('store');
|
||||
@@ -753,7 +795,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTrue($this->response->headers->get('Age') <= 1);
|
||||
$this->assertLessThanOrEqual(1, $this->response->headers->get('Age'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceNotContains('fresh');
|
||||
@@ -791,7 +833,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertNotNull($this->response->headers->get('Last-Modified'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTrue($this->response->headers->get('Age') <= 1);
|
||||
$this->assertLessThanOrEqual(1, $this->response->headers->get('Age'));
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceContains('valid');
|
||||
@@ -799,6 +841,21 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceNotContains('miss');
|
||||
}
|
||||
|
||||
public function testValidatesCachedResponsesUseSameHttpMethod()
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($test) {
|
||||
$test->assertSame('OPTIONS', $request->getMethod());
|
||||
});
|
||||
|
||||
// build initial request
|
||||
$this->request('OPTIONS', '/');
|
||||
|
||||
// build subsequent request
|
||||
$this->request('OPTIONS', '/');
|
||||
}
|
||||
|
||||
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
|
||||
{
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
@@ -826,7 +883,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertNotNull($this->response->headers->get('ETag'));
|
||||
$this->assertNotNull($this->response->headers->get('X-Content-Digest'));
|
||||
$this->assertTrue($this->response->headers->get('Age') <= 1);
|
||||
$this->assertLessThanOrEqual(1, $this->response->headers->get('Age'));
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceContains('valid');
|
||||
@@ -834,6 +891,40 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceNotContains('miss');
|
||||
}
|
||||
|
||||
public function testServesResponseWhileFreshAndRevalidatesWithLastModifiedInformation()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) {
|
||||
$response->setSharedMaxAge(10);
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
|
||||
// prime the cache
|
||||
$this->request('GET', '/');
|
||||
|
||||
// next request before s-maxage has expired: Serve from cache
|
||||
// without hitting the backend
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
sleep(15); // expire the cache
|
||||
|
||||
$this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time) {
|
||||
$this->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
|
||||
});
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
$this->assertTraceContains('valid');
|
||||
}
|
||||
|
||||
public function testReplacesCachedResponsesWhenValidationResultsInNon304Response()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
@@ -903,7 +994,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('', $this->response->getContent());
|
||||
$this->assertEquals(strlen('Hello World'), $this->response->headers->get('Content-Length'));
|
||||
$this->assertEquals(\strlen('Hello World'), $this->response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testSendsNoContentWhenFresh()
|
||||
@@ -1079,7 +1170,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array('Cache-Control' => 's-maxage=300'),
|
||||
'headers' => array('Cache-Control' => 's-maxage=200'),
|
||||
),
|
||||
array(
|
||||
'status' => 200,
|
||||
@@ -1093,8 +1184,33 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->request('GET', '/', array(), array(), true);
|
||||
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
|
||||
|
||||
// check for 100 or 99 as the test can be executed after a second change
|
||||
$this->assertTrue(in_array($this->response->getTtl(), array(99, 100)));
|
||||
$this->assertEquals(100, $this->response->getTtl());
|
||||
}
|
||||
|
||||
public function testEsiCacheSendsTheLowestTtlForHeadRequests()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'I am a long-lived master response, but I embed a short-lived resource: <esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'I am a short-lived resource',
|
||||
'headers' => array('Cache-Control' => 's-maxage=100'),
|
||||
),
|
||||
);
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertEquals(100, $this->response->getTtl());
|
||||
}
|
||||
|
||||
public function testEsiCacheForceValidation()
|
||||
@@ -1130,6 +1246,37 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
|
||||
public function testEsiCacheForceValidationForHeadRequests()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'I am the master response and use expiration caching, but I embed another resource: <esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'I am the embedded resource and use validation caching',
|
||||
'headers' => array('ETag' => 'foobar'),
|
||||
),
|
||||
);
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
|
||||
// The response has been assembled from expiration and validation based resources
|
||||
// This can neither be cached nor revalidated, so it should be private/no cache
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertNull($this->response->getTtl());
|
||||
$this->assertTrue($this->response->mustRevalidate());
|
||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
|
||||
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-cache'));
|
||||
}
|
||||
|
||||
public function testEsiRecalculateContentLengthHeader()
|
||||
{
|
||||
$responses = array(
|
||||
@@ -1138,7 +1285,6 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
'body' => '<esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'Content-Length' => 26,
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
@@ -1156,69 +1302,105 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertEquals(12, $this->response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testEsiRecalculateContentLengthHeaderForHeadRequest()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'Content-Length' => 26,
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
|
||||
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
|
||||
// "The Content-Length entity-header field indicates the size of the entity-body,
|
||||
// in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD
|
||||
// method, the size of the entity-body that would have been sent had the request
|
||||
// been a GET."
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertEquals(12, $this->response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testClientIpIsAlwaysLocalhostForForwardedRequests()
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
|
||||
$this->assertEquals('127.0.0.1', $this->kernel->getBackendRequest()->server->get('REMOTE_ADDR'));
|
||||
$this->kernel->assert(function ($backendRequest) {
|
||||
$this->assertSame('127.0.0.1', $backendRequest->server->get('REMOTE_ADDR'));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getTrustedProxyData
|
||||
*/
|
||||
public function testHttpCacheIsSetAsATrustedProxy(array $existing, array $expected)
|
||||
public function testHttpCacheIsSetAsATrustedProxy(array $existing)
|
||||
{
|
||||
Request::setTrustedProxies($existing);
|
||||
Request::setTrustedProxies($existing, Request::HEADER_X_FORWARDED_ALL);
|
||||
|
||||
$this->setNextResponse();
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
$this->assertSame($existing, Request::getTrustedProxies());
|
||||
|
||||
$this->assertEquals($expected, Request::getTrustedProxies());
|
||||
$existing = array_unique(array_merge($existing, array('127.0.0.1')));
|
||||
$this->kernel->assert(function ($backendRequest) use ($existing) {
|
||||
$this->assertSame($existing, Request::getTrustedProxies());
|
||||
$this->assertsame('10.0.0.1', $backendRequest->getClientIp());
|
||||
});
|
||||
|
||||
Request::setTrustedProxies(array(), -1);
|
||||
}
|
||||
|
||||
public function getTrustedProxyData()
|
||||
{
|
||||
return array(
|
||||
array(array(), array('127.0.0.1')),
|
||||
array(array('10.0.0.2'), array('10.0.0.2', '127.0.0.1')),
|
||||
array(array('10.0.0.2', '127.0.0.1'), array('10.0.0.2', '127.0.0.1')),
|
||||
array(array()),
|
||||
array(array('10.0.0.2')),
|
||||
array(array('10.0.0.2', '127.0.0.1')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getXForwardedForData
|
||||
* @dataProvider getForwardedData
|
||||
*/
|
||||
public function testXForwarderForHeaderForForwardedRequests($xForwardedFor, $expected)
|
||||
public function testForwarderHeaderForForwardedRequests($forwarded, $expected)
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$server = array('REMOTE_ADDR' => '10.0.0.1');
|
||||
if (false !== $xForwardedFor) {
|
||||
$server['HTTP_X_FORWARDED_FOR'] = $xForwardedFor;
|
||||
if (null !== $forwarded) {
|
||||
Request::setTrustedProxies($server, -1);
|
||||
$server['HTTP_FORWARDED'] = $forwarded;
|
||||
}
|
||||
$this->request('GET', '/', $server);
|
||||
|
||||
$this->assertEquals($expected, $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For'));
|
||||
$this->kernel->assert(function ($backendRequest) use ($expected) {
|
||||
$this->assertSame($expected, $backendRequest->headers->get('Forwarded'));
|
||||
});
|
||||
|
||||
Request::setTrustedProxies(array(), -1);
|
||||
}
|
||||
|
||||
public function getXForwardedForData()
|
||||
public function getForwardedData()
|
||||
{
|
||||
return array(
|
||||
array(false, '10.0.0.1'),
|
||||
array('10.0.0.2', '10.0.0.2, 10.0.0.1'),
|
||||
array('10.0.0.2, 10.0.0.3', '10.0.0.2, 10.0.0.3, 10.0.0.1'),
|
||||
array(null, 'for="10.0.0.1";host="localhost";proto=http'),
|
||||
array('for=10.0.0.2', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.1"'),
|
||||
array('for=10.0.0.2, for=10.0.0.3', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.3", for="10.0.0.1"'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testXForwarderForHeaderForPassRequests()
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$server = array('REMOTE_ADDR' => '10.0.0.1');
|
||||
$this->request('POST', '/', $server);
|
||||
|
||||
$this->assertEquals('10.0.0.1', $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For'));
|
||||
}
|
||||
|
||||
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
@@ -1246,6 +1428,86 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertNull($this->response->getETag());
|
||||
$this->assertNull($this->response->getLastModified());
|
||||
}
|
||||
|
||||
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponsesAndHeadRequest()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$responses = array(
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/hey" />',
|
||||
'headers' => array(
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
'ETag' => 'hey',
|
||||
'Last-Modified' => $time->format(DATE_RFC2822),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'status' => 200,
|
||||
'body' => 'Hey!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertNull($this->response->getETag());
|
||||
$this->assertNull($this->response->getLastModified());
|
||||
}
|
||||
|
||||
public function testDoesNotCacheOptionsRequest()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'get');
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'options');
|
||||
$this->request('OPTIONS', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertSame('get', $this->response->getContent());
|
||||
}
|
||||
|
||||
public function testUsesOriginalRequestForSurrogate()
|
||||
{
|
||||
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
|
||||
$store = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\StoreInterface')->getMock();
|
||||
|
||||
$kernel
|
||||
->expects($this->exactly(2))
|
||||
->method('handle')
|
||||
->willReturnCallback(function (Request $request) {
|
||||
$this->assertSame('127.0.0.1', $request->server->get('REMOTE_ADDR'));
|
||||
|
||||
return new Response();
|
||||
});
|
||||
|
||||
$cache = new HttpCache($kernel,
|
||||
$store,
|
||||
new Esi()
|
||||
);
|
||||
|
||||
$request = Request::create('/');
|
||||
$request->server->set('REMOTE_ADDR', '10.0.0.1');
|
||||
|
||||
// Main request
|
||||
$cache->handle($request, HttpKernelInterface::MASTER_REQUEST);
|
||||
|
||||
// Main request was now modified by HttpCache
|
||||
// The surrogate will ask for the request using $this->cache->getRequest()
|
||||
// which MUST return the original request so the surrogate
|
||||
// can actually behave like a reverse proxy like e.g. Varnish would.
|
||||
$this->assertSame('10.0.0.1', $cache->getRequest()->getClientIp());
|
||||
$this->assertSame('10.0.0.1', $cache->getRequest()->server->get('REMOTE_ADDR'));
|
||||
|
||||
// Surrogate request
|
||||
$cache->handle($request, HttpKernelInterface::SUB_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
class TestKernel implements HttpKernelInterface
|
||||
|
Reference in New Issue
Block a user