diff --git a/code/site/components/com_pages/controller/abstract.php b/code/site/components/com_pages/controller/abstract.php index 98e23550..1d2991ac 100644 --- a/code/site/components/com_pages/controller/abstract.php +++ b/code/site/components/com_pages/controller/abstract.php @@ -64,30 +64,6 @@ public function getModel() return $this->_model; } - protected function _actionRender(KControllerContextInterface $context) - { - if(!$context->response->isError()) - { - if($route = $context->router->generate($this->getPage())) - { - $location = $context->router->qualify($route); - - /** - * If Content-Location is included in a 2xx (Successful) response message and its value refers (after - * conversion to absolute form) to a URI that is the same as the effective request URI, then the recipient - * MAY consider the payload to be a current representation of that resource at the time indicated by the - * message origination date - * - * See: https://tools.ietf.org/html/rfc7231#section-3.1.4.2 - */ - $context->response->headers->set('Content-Location', $location); - } - } - - return parent::_actionRender($context); - } - - protected function _actionBrowse(KControllerContextInterface $context) { $entity = $this->getModel()->fetch(); diff --git a/code/site/components/com_pages/dispatcher/behavior/cacheable.php b/code/site/components/com_pages/dispatcher/behavior/cacheable.php index 1491e038..046489cd 100644 --- a/code/site/components/com_pages/dispatcher/behavior/cacheable.php +++ b/code/site/components/com_pages/dispatcher/behavior/cacheable.php @@ -121,7 +121,7 @@ protected function _actionValidate(KDispatcherContextInterface $context) $response->setDate(new DateTime('now')); $response->headers->set('Age', null); $response->headers->set('Cache-Status', self::CACHE_REVALIDATED, false); - $response->headers->set('Content-Location', (string) $this->getContentLocation()); + //$response->headers->set('Content-Location', (string) $this->getContentLocation()); } else $response->headers->set('Age', max(time() - $response->getDate()->format('U'), 0)); @@ -190,8 +190,8 @@ protected function _actionCache(KDispatcherContextInterface $context) } $data = array( - 'id' => $this->getContentLocation()->toString(KHttpUrl::PATH + KHttpUrl::QUERY), - 'url' => rtrim((string) $this->getContentLocation(), '/'), + 'id' => $this->getCacheUrl()->toString(KHttpUrl::PATH + KHttpUrl::QUERY), + 'url' => rtrim((string) $this->getCacheUrl(), '/'), 'validators' => $this->getCacheValidators(), 'status' => !$response->isNotModified() ? $response->getStatusCode() : '200', 'token' => $this->getCacheToken(), @@ -341,19 +341,8 @@ public function getCacheToken() return $token; } - public function getContentLocation() + public function getCacheUrl() { - /** - * Get content location - * - * If Content-Location is included in a 2xx (Successful) response message and its value refers (after - * conversion to absolute form) to a URI that is the same as the effective request URI, then the recipient - * MAY consider the payload to be a current representation of that resource at the time indicated by the - * message origination date. For a GET (Section 4.3.1) or HEAD (Section 4.3.2) request, this is the same - * as the default semantics when no Content-Location is provided by the server. - * - * See: https://tools.ietf.org/html/rfc7231#section-3.1.4.2 - */ if(!$location = $this->getResponse()->headers->get('Content-Location')) { $location = $this->getRequest()->getUrl() @@ -366,7 +355,7 @@ public function getContentLocation() public function locateCache($url = null) { - $key = $url ?? $this->getContentLocation()->toString(KHttpUrl::PATH + KHttpUrl::QUERY); + $key = $url ?? $this->getCacheUrl()->toString(KHttpUrl::PATH + KHttpUrl::QUERY); $file = $this->getConfig()->cache_path . '/response_' . crc32($key) . '.php'; return $file; @@ -465,7 +454,7 @@ public function storeCache($data) { if($this->getConfig()->cache) { - $url = (string) $this->getContentLocation(); + $url = (string) $this->getCacheUrl(); $path = $this->getConfig()->cache_path; if(!is_dir($path) && (false === @mkdir($path, 0777, true) && !is_dir($path))) { diff --git a/code/site/components/com_pages/dispatcher/http.php b/code/site/components/com_pages/dispatcher/http.php index 9548fe7e..7ed2a032 100644 --- a/code/site/components/com_pages/dispatcher/http.php +++ b/code/site/components/com_pages/dispatcher/http.php @@ -177,6 +177,22 @@ protected function _beforeDispatch(KDispatcherContextInterface $context) throw new KHttpExceptionNotAcceptable('Format not supported'); } } + + /** + * If Content-Location is included in a 2xx (Successful) response message and its value refers (after + * conversion to absolute form) to a URI that is the same as the effective request URI, then the recipient + * MAY consider the payload to be a current representation of that resource at the time indicated by the + * message origination date + * + * See: https://tools.ietf.org/html/rfc7231#section-3.1.4.2 + */ + if($context->request->isSafe()) + { + $route = $context->router->generate($route); + $location = $context->router->qualify($route); + + $context->response->headers->set('Content-Location', (string) $location); + } } protected function _actionDispatch(KDispatcherContextInterface $context) diff --git a/code/site/components/com_pages/event/subscriber/staticcache.php b/code/site/components/com_pages/event/subscriber/staticcache.php index f2719931..3e304e6e 100644 --- a/code/site/components/com_pages/event/subscriber/staticcache.php +++ b/code/site/components/com_pages/event/subscriber/staticcache.php @@ -18,7 +18,7 @@ public function onAfterDispatcherCache(KEventInterface $event) $response = $dispatcher->getResponse(); //Only cache static pages without a query string - if($event->result && !$dispatcher->getContentLocation()->getQuery() && $this->getConfig()->cache_path) + if($event->result && !$dispatcher->getCacheUrl()->getQuery() && $this->getConfig()->cache_path) { $file = $this->getFilePath($dispatcher); $dir = dirname($file); @@ -89,7 +89,7 @@ public function getCachePath() public function getFilePath(ComPagesDispatcherHttp $dispatcher) { - $path = $dispatcher->getContentLocation()->getPath(true); + $path = $dispatcher->getCacheUrl()->getPath(true); $filename = array_pop($path); $format = pathinfo($filename, PATHINFO_EXTENSION);