You are here

public function DuplicateContentPreventionMiddleware::handle in CDN 8.3

File

src/StackMiddleware/DuplicateContentPreventionMiddleware.php, line 119

Class

DuplicateContentPreventionMiddleware
Redirects CDN user agents' requests for HTML to the canonical location.

Namespace

Drupal\cdn\StackMiddleware

Code

public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE) {
  $redirect_url = $this
    ->getRedirectUrl($request);
  if ($redirect_url) {
    return new RedirectResponse($redirect_url, 301, [
      // @see http://googlewebmastercentral.blogspot.com/2011/06/supporting-relcanonical-http-headers.html
      'Link' => '<' . $redirect_url . '>; rel="canonical"',
      // Informative header to simplify debugging.
      'Drupal-CDN-Redirect' => 'duplicate content prevention',
    ]);
  }
  return $this->httpKernel
    ->handle($request, $type, $catch);
}