Skip to content

Commit

Permalink
#645 - Set canonical url in dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
johanjanssens committed Apr 12, 2021
1 parent e6c747b commit d0fe8bd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
24 changes: 0 additions & 24 deletions code/site/components/com_pages/controller/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions code/site/components/com_pages/dispatcher/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d0fe8bd

Please sign in to comment.