8000 Move duplicated logic from Esi/Ssi::process in AbstractSurrogate::rem… · symfony/symfony@1e8040d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e8040d

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

File tree

3 files changed

+29
-23
lines changed

3 files changed

+29
-23
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ public function needsParsing(Response $response)
8787
return (bool) preg_match($pattern, $control);
8888
}
8989

90+
9091
/**
9192
* {@inheritdoc}
9293
*/
9394
public function handle(HttpCache $cache, $uri, $alt, $ignoreErrors)
9495
{
95-
$subRequest = Request::create($uri, 'get', array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
96+
$subRequest = Request::create($uri, Request::METHOD_GET, array(), $cache->getRequest()->cookies->all(), array(), $cache->getRequest()->server->all());
9697

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

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,8 @@ public function process(Request $request, Response $response)
108108

109109
$response->setContent($content);
110110
$response->headers->set('X-Body-Eval', 'ESI');
111-
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-
}
111+
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)
0