Skip to content

Commit

Permalink
request creds
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Nov 21, 2023
1 parent 0c409b6 commit f87ce13
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 68 deletions.
16 changes: 0 additions & 16 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
use craft\services\ImageTransforms;
use craft\utilities\ClearCaches;
use craft\web\Application as WebApplication;
use craft\web\Response as WebResponse;
use craft\web\twig\variables\CraftVariable;
use craft\web\View;
use Illuminate\Support\Collection;
use yii\base\InvalidConfigException;
use yii\web\Response as YiiWebResponse;

/**
* @property-read Config $config
Expand Down Expand Up @@ -197,14 +195,6 @@ protected function bootstrapCloud(ConsoleApplication|WebApplication $app): void
],
);

if ($this->getConfig()->useMutex) {
Event::on(
WebResponse::class,
YiiWebResponse::EVENT_BEFORE_SEND,
[$this->get('mutex'), 'handleBeforeSend'],
);
}

$this->setComponents([
'staticCaching' => StaticCaching::class,
]);
Expand Down Expand Up @@ -232,12 +222,6 @@ protected function bootstrapCloud(ConsoleApplication|WebApplication $app): void
ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
[$this->get('staticCaching'), 'handleRegisterCacheOptions'],
);

Event::on(
WebResponse::class,
YiiWebResponse::EVENT_BEFORE_SEND,
[$this->get('staticCaching'), 'handleBeforeSend'],
);
}

protected function validateConfig(): void
Expand Down
22 changes: 1 addition & 21 deletions src/Mutex.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Craft;
use craft\mutex\MutexTrait;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Support\Collection;
use yii\base\Exception;

class Mutex extends \yii\mutex\Mutex
Expand Down Expand Up @@ -55,6 +54,7 @@ protected function releaseLock($name): bool
->request('HEAD', (string) $url, [
'headers' => [
HeaderEnum::MUTEX_RELEASE_LOCK->value => $name,
HeaderEnum::AUTHORIZATION->value => "bearer xxx",
],
]);

Expand All @@ -65,24 +65,4 @@ protected function releaseLock($name): bool
return false;
}
}

public function handleBeforeSend(): void
{
$headers = Collection::make(Craft::$app->getRequest()->getHeaders())
->only([
HeaderEnum::MUTEX_ACQUIRE_LOCK->value,
HeaderEnum::MUTEX_RELEASE_LOCK->value,
]);

if ($headers->isNotEmpty()) {
Craft::$app->getResponse()->setNoCacheHeaders();
}

$headers->each(function($value, $key) {
Craft::$app->getResponse()->getHeaders()->setDefault(
$key,
$value,
);
});
}
}
16 changes: 1 addition & 15 deletions src/StaticCaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ public function handleAfterRenderPageTemplate(TemplateEvent $event): void
$this->addCacheTagsToResponse($dependency?->tags, $duration);
}

public function handleBeforeSend(): void
{
$purgeHeader = Craft::$app->getRequest()->getHeaders()->get(HeaderEnum::CACHE_PURGE->value);

// TODO: check authorization header
if ($purgeHeader) {
Craft::$app->getResponse()->setNoCacheHeaders();
Craft::$app->getResponse()->getHeaders()->setDefault(
HeaderEnum::CACHE_PURGE->value,
$purgeHeader,
);
}
}

public function handleInvalidateCaches(InvalidateElementCachesEvent $event): void
{
if (Craft::$app->getResponse() instanceof WebResponse) {
Expand Down Expand Up @@ -102,13 +88,13 @@ public function purgeAll(): void
->request('HEAD', (string) $url, [
'headers' => [
HeaderEnum::CACHE_PURGE->value => '*',
HeaderEnum::AUTHORIZATION->value => "bearer xxx",
],
]);

return;
}


Craft::$app->getResponse()->getHeaders()->set(
HeaderEnum::CACHE_PURGE->value, '*',
);
Expand Down
16 changes: 0 additions & 16 deletions src/controllers/ApiController.php

This file was deleted.

0 comments on commit f87ce13

Please sign in to comment.