changeset 560:862a0370801f

support X-Forwarded-Proto & X-Forwarded-Host
author Alain Mazy <am@osimis.io>
date Mon, 24 Apr 2023 10:42:37 +0200
parents ac897682535d
children 794dc1f9ea6e
files NEWS Plugin/Configuration.cpp
diffstat 2 files changed, 34 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Mon Apr 24 10:42:17 2023 +0200
+++ b/NEWS	Mon Apr 24 10:42:37 2023 +0200
@@ -1,8 +1,15 @@
+Pending changes in the mainline
+===============================
+
+* Support "X-Forwarded-Host" and "X-Forwarded-Proto" headers to compute BulkDataURI.
+
+
 Version 1.13 (2023-02-03)
 =========================
 
 * Use Orthanc SDK 1.11.3 to avoid a crash in Stow-RS jobs.
 
+
 Version 1.12 (2022-10-27)
 =========================
 
--- a/Plugin/Configuration.cpp	Mon Apr 24 10:42:17 2023 +0200
+++ b/Plugin/Configuration.cpp	Mon Apr 24 10:42:37 2023 +0200
@@ -522,6 +522,18 @@
       std::string host = dicomWebConfiguration_->GetStringValue("Host", "");
       bool https = dicomWebConfiguration_->GetBooleanValue("Ssl", false);
 
+      std::string forwardedHost, forwardedProto;
+      if (host.empty() &&
+          LookupHttpHeader2(forwardedHost, headers, "x-forwarded-host") &&
+          LookupHttpHeader2(forwardedProto, headers, "x-forwarded-proto"))
+      {
+        // There is a "X-Forwarded-Proto" and a "X-Forwarded-Host" HTTP header in the query
+        // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
+        
+        host = Orthanc::Toolbox::StripSpaces(forwardedHost);
+        https = IsHttpsProto(Orthanc::Toolbox::StripSpaces(forwardedProto), https);
+      }
+
       std::string forwarded;
       if (host.empty() &&
           LookupHttpHeader2(forwarded, headers, "forwarded"))
@@ -588,6 +600,21 @@
         headers["Host"] = value;
       }
 
+      if (LookupHttpHeader(value, request, "x-forwarded-host"))
+      {
+        headers["X-Forwarded-Host"] = value;
+      }
+
+      if (LookupHttpHeader(value, request, "x-forwarded-proto"))
+      {
+        headers["X-Forwarded-Proto"] = value;
+      }
+
+      if (LookupHttpHeader(value, request, "host"))
+      {
+        headers["Host"] = value;
+      }
+
       return GetBasePublicUrl(headers);
     }