Skip to content

Commit

Permalink
Merge 490edc8 into 3c4940a
Browse files Browse the repository at this point in the history
  • Loading branch information
swordfox committed Nov 1, 2023
2 parents 3c4940a + 490edc8 commit 9431565
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
"email": "tim@dorset-digital.net"
}
],
"require": {
"silverstripe/vendor-plugin": "^1.0",
"silverstripe/cms": "^4.0"
},
"license": "BSD-3-Clause",
"autoload": {
"psr-4": {
Expand Down
10 changes: 8 additions & 2 deletions src/CDNMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function process(HTTPRequest $request, callable $delegate)

if ($this->getIsAdmin($request) === false) {
$body = $response->getBody();
$this->rewriteTags($body, $response);
$this->rewriteTags($body);
$this->addPrefetch($body, $response);
$response->setBody($body);
}
Expand Down Expand Up @@ -122,8 +122,10 @@ private function canRun()
* @param $body
* @param $response
*/
private function rewriteTags(&$body, &$response)
private function rewriteTags(&$body)
{
$body = ($body ?: '');

$cdn = $this->config()->get('cdn_domain');
$subDir = $this->getSubdirectory();
$prefixes = $this->config()->get('rewrites');
Expand All @@ -136,6 +138,7 @@ private function rewriteTags(&$body, &$response)
'src="/' . $subDir . $cleanPrefix . '/',
'src=\"/' . $subDir . $cleanPrefix . '/',
'href="/' . $subDir . $cleanPrefix . '/',
'background-image: url(/' . $subDir . $cleanPrefix . '/',
Director::absoluteBaseURL() . $cleanPrefix . '/'
];

Expand All @@ -144,6 +147,7 @@ private function rewriteTags(&$body, &$response)
'src="' . $cdn . '/' . $subDir . $cleanPrefix . '/',
'src=\"' . $cdn . '/' . $subDir . $cleanPrefix . '/',
'href="' . $cdn . '/' . $subDir . $cleanPrefix . '/',
'background-image: url(' . $cdn . '/' . $subDir . $cleanPrefix . '/',
$cdn . '/' . $subDir . $cleanPrefix . '/'
];

Expand All @@ -154,6 +158,8 @@ private function rewriteTags(&$body, &$response)

private function addPrefetch(&$body, &$response)
{
$body = ($body ?: '');

if ($this->config()->get('add_prefetch') === true) {
$prefetchTag = $this->getPrefetchTag();
$body = str_replace('<head>', "<head>" . $prefetchTag, $body);
Expand Down

0 comments on commit 9431565

Please sign in to comment.