From d0fe8bd2873d4f341516527688f5cc28945a1199 Mon Sep 17 00:00:00 2001 From: Johan Janssens Date: Mon, 12 Apr 2021 11:33:28 +0200 Subject: [PATCH] #645 - Set canonical url in dispatcher --- .../com_pages/controller/abstract.php | 24 ------------------- .../components/com_pages/dispatcher/http.php | 16 +++++++++++++ 2 files changed, 16 insertions(+), 24 deletions(-) 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/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)