// we don't use a proper XML parser here as we can have ESI tags in a plain text response
$content =
$response->
getContent();
$content =
preg_replace('#<esi\:remove>.*?</esi\:remove>#s', '',
$content);
$content =
preg_replace('#<esi\:comment[^>]+>#s', '',
$content);
$boundary = self::
generateBodyEvalBoundary();
$chunks =
preg_split('#<esi\:include\s+(.*?)\s*(?:/|</esi\:include)>#',
$content, -1, \PREG_SPLIT_DELIM_CAPTURE
);
$i = 1;
while (isset($chunks[$i])) { $options =
[];
preg_match_all('/(src|onerror|alt)="([^"]*?)"/',
$chunks[$i],
$matches, \PREG_SET_ORDER
);
foreach ($matches as $set) { $options[$set[1
]] =
$set[2
];
} if (!
isset($options['src'
])) { throw new \
RuntimeException('Unable to process an ESI tag without a "src" attribute.'
);
} $chunks[$i] =
$boundary.
$options['src'
]."\n".
($options['alt'
] ?? ''
)."\n".
('continue'
=== ($options['onerror'
] ?? ''
))."\n";