Skip to content

Commit cd802cf

Browse files
committed
Move duplicated logic from Esi/Ssi::process in AbstractSurrogate::removeFromControl
Fabbot fixes
1 parent fb6860c commit cd802cf

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/Symfony/Component/HttpKernel/HttpCache/AbstractSurrogate.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function needsParsing(Response $response)
9292
*/
9393
public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
9494
{
95-
$subRequest = Request::create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
95+
$subRequest = Request::create($uri, Request::METHOD_GET, array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
9696

9797
try {
9898
$response = $cache->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true);
@@ -112,4 +112,27 @@ public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
112112
}
113113
}
114114
}
115+
116+
/**
117+
* Remove the Surrogate from the Surrogate-Control header.
118+
*
119+
* @param Response $response
120+
*/
121+
protected function removeFromControl(Response $response)
122+
{
123+
if (!$response->headers->has('Surrogate-Control')) {
124+
return;
125+
}
126+
127+
$value = $response->headers->get('Surrogate-Control');
128+
$upperName = strtoupper($this->getName());
129+
130+
if (sprintf('content="%s/1.0"', $upperName) == $value) {
131+
$response->headers->remove('Surrogate-Control');
132+
} elseif (preg_match(sprintf('#,\s*content="%s/1.0"#', $upperName), $value)) {
133+
$response->headers->set('Surrogate-Control', preg_replace(sprintf('#,\s*content="%s/1.0"#', $upperName), '', $value));
134+
} elseif (preg_match(sprintf('#content="%s/1.0",\s*#', $upperName), $value)) {
135+
$response->headers->set('Surrogate-Control', preg_replace(sprintf('#content="%s/1.0",\s*#', $upperName), '', $value));
136+
}
137+
}
115138
}

src/Symfony/Component/HttpKernel/HttpCache/Esi.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,7 @@ public function process(Request $request, Response $response)
109109
$response->setContent($content);
110110
$response->headers->set('X-Body-Eval', 'ESI');
111111

112-
// remove ESI/1.0 from the Surrogate-Control header
113-
if ($response->headers->has('Surrogate-Control')) {
114-
$value = $response->headers->get('Surrogate-Control');
115-
if ('content="ESI/1.0"' == $value) {
116-
$response->headers->remove('Surrogate-Control');
117-
} elseif (preg_match('#,\s*content="ESI/1.0"#', $value)) {
118-
$response->headers->set('Surrogate-Control', preg_replace('#,\s*content="ESI/1.0"#', '', $value));
119-
} elseif (preg_match('#content="ESI/1.0",\s*#', $value)) {
120-
$response->headers->set('Surrogate-Control', preg_replace('#content="ESI/1.0",\s*#', '', $value));
121-
}
122-
}
112+
// remove SSI/1.0 from the Surrogate-Control header
113+
$this->removeFromControl($response);
123114
}
124115
}

src/Symfony/Component/HttpKernel/HttpCache/Ssi.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,6 @@ public function process(Request $request, Response $response)
9393
$response->headers->set('X-Body-Eval', 'SSI');
9494

9595
// remove SSI/1.0 from the Surrogate-Control header
96-
if ($response->headers->has('Surrogate-Control')) {
97-
$value = $response->headers->get('Surrogate-Control');
98-
if ('content="SSI/1.0"' == $value) {
99-
$response->headers->remove('Surrogate-Control');
100-
} elseif (preg_match('#,\s*content="SSI/1.0"#', $value)) {
101-
$response->headers->set('Surrogate-Control', preg_replace('#,\s*content="SSI/1.0"#', '', $value));
102-
} elseif (preg_match('#content="SSI/1.0",\s*#', $value)) {
103-
$response->headers->set('Surrogate-Control', preg_replace('#content="SSI/1.0",\s*#', '', $value));
104-
}
105-
}
96+
$this->removeFromControl($response);
10697
}
10798
}

0 commit comments

Comments
 (0)