|
11 | 11 |
|
12 | 12 | namespace Symfony\Component\HttpKernel\Tests\HttpCache;
|
13 | 13 |
|
| 14 | +use Symfony\Component\HttpKernel\HttpCache\Esi; |
14 | 15 | use Symfony\Component\HttpKernel\HttpCache\HttpCache;
|
15 | 16 | use Symfony\Component\HttpFoundation\Request;
|
16 | 17 | use Symfony\Component\HttpFoundation\Response;
|
| 18 | +use Symfony\Component\HttpKernel\HttpCache\Store; |
| 19 | +use Symfony\Component\HttpKernel\HttpCache\StoreInterface; |
17 | 20 | use Symfony\Component\HttpKernel\HttpKernelInterface;
|
18 | 21 |
|
19 | 22 | /**
|
@@ -1432,6 +1435,42 @@ public function testDoesNotCacheOptionsRequest()
|
1432 | 1435 | $this->assertHttpKernelIsNotCalled();
|
1433 | 1436 | $this->assertSame('get', $this->response->getContent());
|
1434 | 1437 | }
|
| 1438 | + |
| 1439 | + public function testUsesOriginalRequestForSurrogate() |
| 1440 | + { |
| 1441 | + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); |
| 1442 | + $store = $this->getMockBuilder(StoreInterface::class)->getMock(); |
| 1443 | + |
| 1444 | + $kernel |
| 1445 | + ->expects($this->exactly(2)) |
| 1446 | + ->method('handle') |
| 1447 | + ->willReturnCallback(function (Request $request) { |
| 1448 | + $this->assertSame('127.0.0.1', $request->server->get('REMOTE_ADDR')); |
| 1449 | + |
| 1450 | + return new Response(); |
| 1451 | + }); |
| 1452 | + |
| 1453 | + $cache = new HttpCache($kernel, |
| 1454 | + $store, |
| 1455 | + new Esi() |
| 1456 | + ); |
| 1457 | + |
| 1458 | + $request = Request::create('/'); |
| 1459 | + $request->server->set('REMOTE_ADDR', '10.0.0.1'); |
| 1460 | + |
| 1461 | + // Main request |
| 1462 | + $cache->handle($request, HttpKernelInterface::MASTER_REQUEST); |
| 1463 | + |
| 1464 | + // Main request was now modified by HttpCache |
| 1465 | + // The surrogate will ask for the request using $this->cache->getRequest() |
| 1466 | + // which MUST return the original request so the surrogate |
| 1467 | + // can actually behave like a reverse proxy like e.g. Varnish would. |
| 1468 | + $this->assertSame('10.0.0.1', $cache->getRequest()->getClientIp()); |
| 1469 | + $this->assertSame('10.0.0.1', $cache->getRequest()->server->get('REMOTE_ADDR')); |
| 1470 | + |
| 1471 | + // Surrogate request |
| 1472 | + $cache->handle($request, HttpKernelInterface::SUB_REQUEST); |
| 1473 | + } |
1435 | 1474 | }
|
1436 | 1475 |
|
1437 | 1476 | class TestKernel implements HttpKernelInterface
|
|
0 commit comments