Cleaner way to build the canonical URL

This commit is contained in:
Pierre Rudloff 2020-10-22 00:28:36 +02:00
parent 68f2255fa0
commit 110bfc9ff1

View file

@ -13,6 +13,7 @@ use Alltube\Locale;
use Alltube\Middleware\CspMiddleware; use Alltube\Middleware\CspMiddleware;
use Exception; use Exception;
use Slim\Http\StatusCode; use Slim\Http\StatusCode;
use Slim\Http\Uri;
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
use Throwable; use Throwable;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
@ -332,19 +333,11 @@ class FrontController extends BaseController
*/ */
private function getCanonicalUrl(Request $request) private function getCanonicalUrl(Request $request)
{ {
/** @var Uri $uri */
$uri = $request->getUri(); $uri = $request->getUri();
$return = 'https://alltubedownload.net/';
$path = $uri->getPath(); return $uri->withBasePath('')
if ($path != '/') { ->withHost('alltubedownload.net')
$return .= $path; ->withScheme('https');
}
$query = $uri->getQuery();
if (!empty($query)) {
$return .= '?' . $query;
}
return $return;
} }
} }