fix: redirect loop infinito em URLs com cultura
All checks were successful
Deploy QR Rapido / test (push) Successful in 4m46s
Deploy QR Rapido / build-and-push (push) Successful in 12m20s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 3m22s

O middleware redirecionava /pt-BR/* para /pt-BR/* causando
ERR_TOO_MANY_REDIRECTS. Adicionada verificação case-sensitive
para evitar redirect quando URL já está na forma canônica.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Ricardo Carneiro 2026-01-24 21:05:50 -03:00
parent ea6eacc6c6
commit 00c5a132ab

View File

@ -12,7 +12,8 @@ namespace QRRapidoApp.Middleware
{ {
{ "pt", "pt-BR" }, { "pt", "pt-BR" },
{ "pt-br", "pt-BR" }, { "pt-br", "pt-BR" },
{ "es", "es-PY" } { "es", "es-PY" },
{ "es-py", "es-PY" }
}; };
private const string DefaultCulture = "pt-BR"; private const string DefaultCulture = "pt-BR";
@ -91,6 +92,12 @@ namespace QRRapidoApp.Middleware
var firstSegment = segments[0]; var firstSegment = segments[0];
if (_cultureAliases.TryGetValue(firstSegment, out var mappedCulture)) if (_cultureAliases.TryGetValue(firstSegment, out var mappedCulture))
{ {
// Don't redirect if already using the canonical culture (case-sensitive check)
if (firstSegment == mappedCulture)
{
return false;
}
var remainingSegments = segments.Length > 1 var remainingSegments = segments.Length > 1
? "/" + string.Join('/', segments.Skip(1)) ? "/" + string.Join('/', segments.Skip(1))
: string.Empty; : string.Empty;