From 7d21b395346f9a914d9d32a6ac42d18ca4ab7ce0 Mon Sep 17 00:00:00 2001 From: Kukks Date: Sun, 3 Jan 2021 14:29:19 +0100 Subject: [PATCH 1/2] Do not tell browser to redirect if invoice is loaded as a modal fixes #2089 --- BTCPayServer/Hosting/BTCpayMiddleware.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BTCPayServer/Hosting/BTCpayMiddleware.cs b/BTCPayServer/Hosting/BTCpayMiddleware.cs index 7d17ff643..e845fd76e 100644 --- a/BTCPayServer/Hosting/BTCpayMiddleware.cs +++ b/BTCPayServer/Hosting/BTCpayMiddleware.cs @@ -58,7 +58,9 @@ namespace BTCPayServer.Hosting return; } - if (!httpContext.Request.IsOnion() && (httpContext.Request.Headers["Accept"].ToString().StartsWith("text/html", StringComparison.InvariantCulture))) + 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 onionLocation = _Env.OnionUrl + httpContext.Request.GetEncodedPathAndQuery(); httpContext.Response.SetHeader("Onion-Location", onionLocation); From 0a6ea59254e856d859b52878432d3165234ab918 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Tue, 5 Jan 2021 13:44:08 +0900 Subject: [PATCH 2/2] Rewrite the condition to show Onion-Location in a more readable way --- BTCPayServer/Hosting/BTCpayMiddleware.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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);