|
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 | /**
|
@@ -1465,6 +1468,42 @@ public function testDoesNotCacheOptionsRequest()
|
1465 | 1468 | $this->assertHttpKernelIsNotCalled();
|
1466 | 1469 | $this->assertSame('get', $this->response->getContent());
|
1467 | 1470 | }
|
| 1471 | + |
| 1472 | + public function testUsesOriginalRequestForSurrogate() |
| 1473 | + { |
| 1474 | + $kernel = $this->createMock(HttpKernelInterface::class); |
| 1475 | + $store = $this->createMock(StoreInterface::class); |
| 1476 | + |
| 1477 | + $kernel |
| 1478 | + ->expects($this->exactly(2)) |
| 1479 | + ->method('handle') |
| 1480 | + ->willReturnCallback(function (Request $request) { |
| 1481 | + $this->assertSame('127.0.0.1', $request->server->get('REMOTE_ADDR')); |
| 1482 | + |
| 1483 | + return new Response(); |
| 1484 | + }); |
| 1485 | + |
| 1486 | + $cache = new HttpCache($kernel, |
| 1487 | + $store, |
| 1488 | + new Esi() |
| 1489 | + ); |
| 1490 | + |
| 1491 | + $request = Request::create('/'); |
| 1492 | + $request->server->set('REMOTE_ADDR', '10.0.0.1'); |
| 1493 | + |
| 1494 | + // Main request |
| 1495 | + $cache->handle($request, HttpKernelInterface::MASTER_REQUEST); |
| 1496 | + |
| 1497 | + // Main request was now modified by HttpCache |
| 1498 | + // The surrogate will ask for the request using $this->cache->getRequest() |
| 1499 | + // which MUST return the original request so the surrogate |
| 1500 | + // can actually behave like a reverse proxy like e.g. Varnish would. |
| 1501 | + $this->assertSame('10.0.0.1', $cache->getRequest()->getClientIp()); |
| 1502 | + $this->assertSame('10.0.0.1', $cache->getRequest()->server->get('REMOTE_ADDR')); |
| 1503 | + |
| 1504 | + // Surrogate request |
| 1505 | + $cache->handle($request, HttpKernelInterface::SUB_REQUEST); |
| 1506 | + } |
1468 | 1507 | }
|
1469 | 1508 |
|
1470 | 1509 | class TestKernel implements HttpKernelInterface
|
|
0 commit comments