public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)
{
$uri = $request->getUri();
$host = $uri->getHost();
if ($this->addWww) {
if ($this->canAddWww($host)) {
$host = "www.{$host}";
}
} elseif (strpos($host, 'www.') === 0) {
$host = substr($host, 4);
}
//redirect
if ($this->redirectStatus !== false && $uri->getHost() !== $host) {
return $this->getRedirectResponse($request, $uri->withHost($host), $response);
}
return $next($request->withUri($uri->withHost($host)), $response);
}