diff --git a/BTCPayServer/Hosting/BTCpayMiddleware.cs b/BTCPayServer/Hosting/BTCpayMiddleware.cs index e845fd76e..545fc0257 100644 --- a/BTCPayServer/Hosting/BTCpayMiddleware.cs +++ b/BTCPayServer/Hosting/BTCpayMiddleware.cs @@ -58,9 +58,14 @@ namespace BTCPayServer.Hosting return; } - if (!httpContext.Request.IsOnion() && (httpContext.Request.Headers["Accept"].ToString() - .StartsWith("text/html", StringComparison.InvariantCulture) && ( - !httpContext.Request.Query.TryGetValue("view", out var view) || view != "modal"))) + var isHtml = httpContext.Request.Headers.TryGetValue("Accept", out var accept) + && accept.ToString().StartsWith("text/html", StringComparison.OrdinalIgnoreCase); + var isModal = httpContext.Request.Query.TryGetValue("view", out var view) + && view.ToString().Equals("modal", StringComparison.OrdinalIgnoreCase); + if (!string.IsNullOrEmpty(_Env.OnionUrl) && + !httpContext.Request.IsOnion() && + isHtml && + !isModal) { var onionLocation = _Env.OnionUrl + httpContext.Request.GetEncodedPathAndQuery(); httpContext.Response.SetHeader("Onion-Location", onionLocation);