mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-27 20:11:34 +03:00
Reolled-back logic that would have made domains with no specific redirects to not fall back to the default redirects
This commit is contained in:
parent
95ab64ba77
commit
c39e1e649d
2 changed files with 16 additions and 3 deletions
|
@ -27,9 +27,18 @@ class NotFoundRedirectHandler implements MiddlewareInterface
|
||||||
/** @var NotFoundType $notFoundType */
|
/** @var NotFoundType $notFoundType */
|
||||||
$notFoundType = $request->getAttribute(NotFoundType::class);
|
$notFoundType = $request->getAttribute(NotFoundType::class);
|
||||||
$authority = $request->getUri()->getAuthority();
|
$authority = $request->getUri()->getAuthority();
|
||||||
$redirectConfig = $this->domainService->findByAuthority($authority) ?? $this->redirectOptions;
|
$domainSpecificRedirect = $this->resolveDomainSpecificRedirect($authority, $notFoundType);
|
||||||
$redirectResponse = $this->redirectResolver->resolveRedirectResponse($notFoundType, $redirectConfig);
|
|
||||||
|
|
||||||
return $redirectResponse ?? $handler->handle($request);
|
return $domainSpecificRedirect
|
||||||
|
// If we did not find domain-specific redirects for current domain, we try to fall back to default redirects
|
||||||
|
?? $this->redirectResolver->resolveRedirectResponse($notFoundType, $this->redirectOptions)
|
||||||
|
// Ultimately, we just call next handler if no domain-specific redirects or default redirects were found
|
||||||
|
?? $handler->handle($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveDomainSpecificRedirect(string $authority, NotFoundType $notFoundType): ?ResponseInterface
|
||||||
|
{
|
||||||
|
$domain = $this->domainService->findByAuthority($authority);
|
||||||
|
return $domain === null ? null : $this->redirectResolver->resolveRedirectResponse($notFoundType, $domain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,10 @@ class NotFoundRedirectHandlerTest extends TestCase
|
||||||
$domainService->findByAuthority(Argument::cetera())
|
$domainService->findByAuthority(Argument::cetera())
|
||||||
->willReturn(Domain::withAuthority(''))
|
->willReturn(Domain::withAuthority(''))
|
||||||
->shouldBeCalledOnce();
|
->shouldBeCalledOnce();
|
||||||
|
$resolver->resolveRedirectResponse(
|
||||||
|
Argument::type(NotFoundType::class),
|
||||||
|
Argument::type(NotFoundRedirectOptions::class),
|
||||||
|
)->willReturn(null)->shouldBeCalledOnce();
|
||||||
$resolver->resolveRedirectResponse(Argument::type(NotFoundType::class), Argument::type(Domain::class))
|
$resolver->resolveRedirectResponse(Argument::type(NotFoundType::class), Argument::type(Domain::class))
|
||||||
->willReturn(null)
|
->willReturn(null)
|
||||||
->shouldBeCalledOnce();
|
->shouldBeCalledOnce();
|
||||||
|
|
Loading…
Add table
Reference in a new issue