# HG changeset patch # User Alain Mazy # Date 1682325757 -7200 # Node ID 862a0370801f9317bf49b58e3f8042745bae6330 # Parent ac897682535dc37ea9cda4bb487d56ad0da682f7 support X-Forwarded-Proto & X-Forwarded-Host diff -r ac897682535d -r 862a0370801f NEWS --- 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) ========================= diff -r ac897682535d -r 862a0370801f Plugin/Configuration.cpp --- 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); }