Skip to content

Commit

Permalink
Add check to prevent minification of XML sitemaps
Browse files Browse the repository at this point in the history
  • Loading branch information
DorsetDigital committed Oct 29, 2020
1 parent 4f1d7cc commit 8122dca
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function process(HTTPRequest $request, callable $delegate)

if (($this->canRun() === true) && ($response !== null)) {

if ($this->getIsAdmin($request) === false) {
if (($this->getIsAdmin($request) === false) && ($this->getIsSitemap($request) === false)) {
$body = $response->getBody();
$minifier = new HtmlMin();
$minBody = $minifier->minify($body);
Expand Down Expand Up @@ -87,4 +87,18 @@ private function getIsAdmin(HTTPRequest $request)
}
return false;
}

/**
* Checks if the current request is for a sitemap file
* @param HTTPRequest $request
* @return bool
*/
private function getIsSitemap(HTTPRequest $request)
{
$currentPath = $request->getURL();
if (stristr($currentPath, 'sitemap.xml')) {
return true;
}
return false;
}
}

0 comments on commit 8122dca

Please sign in to comment.