Replaces a Response ESI tags with the included resource content.
Request $request A Request instance:
Response $response A Response instance:
public function process(Request $request, Response $response) {
$this->request = $request;
$type = $response->headers
->get('Content-Type');
if (empty($type)) {
$type = 'text/html';
}
$parts = explode(';', $type);
if (!in_array($parts[0], $this->contentTypes)) {
return $response;
}
// we don't use a proper XML parser here as we can have ESI tags in a plain text response
$content = $response
->getContent();
$content = str_replace(array(
'<?',
'<%',
), array(
'<?php echo "<?"; ?>',
'<?php echo "<%"; ?>',
), $content);
$content = preg_replace_callback('#<esi\\:include\\s+(.*?)\\s*(?:/|</esi\\:include)>#', array(
$this,
'handleEsiIncludeTag',
), $content);
$content = preg_replace('#<esi\\:comment[^>]*(?:/|</esi\\:comment)>#', '', $content);
$content = preg_replace('#<esi\\:remove>.*?</esi\\:remove>#', '', $content);
$response
->setContent($content);
$response->headers
->set('X-Body-Eval', 'ESI');
// remove ESI/1.0 from the Surrogate-Control header
if ($response->headers
->has('Surrogate-Control')) {
$value = $response->headers
->get('Surrogate-Control');
if ('content="ESI/1.0"' == $value) {
$response->headers
->remove('Surrogate-Control');
}
elseif (preg_match('#,\\s*content="ESI/1.0"#', $value)) {
$response->headers
->set('Surrogate-Control', preg_replace('#,\\s*content="ESI/1.0"#', '', $value));
}
elseif (preg_match('#content="ESI/1.0",\\s*#', $value)) {
$response->headers
->set('Surrogate-Control', preg_replace('#content="ESI/1.0",\\s*#', '', $value));
}
}
}