changeset 1845:ca85b6d60bca

removed duplicate slash in DICOMweb sources
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 24 Jun 2021 16:46:22 +0200
parents 58049bdebdc3
children 2789b4b0e0a8
files OrthancStone/Sources/Loaders/DicomSource.cpp
diffstat 1 files changed, 37 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancStone/Sources/Loaders/DicomSource.cpp	Thu Jun 24 14:48:22 2021 +0200
+++ b/OrthancStone/Sources/Loaders/DicomSource.cpp	Thu Jun 24 16:46:22 2021 +0200
@@ -32,10 +32,9 @@
 
 namespace OrthancStone
 {
-  static std::string EncodeGetArguments(const std::string& uri,
-                                        const std::map<std::string, std::string>& arguments)
+  static std::string EncodeGetArguments(const std::map<std::string, std::string>& arguments)
   {
-    std::string s = uri;
+    std::string s;
     bool first = true;
 
     for (std::map<std::string, std::string>::const_iterator
@@ -60,6 +59,39 @@
   }
 
 
+  static std::string AddUriSuffix(const std::string& base,
+                                  const std::string& suffix)
+  {
+    if (base.empty())
+    {
+      return suffix;
+    }
+    else if (suffix.empty())
+    {
+      return base;
+    }
+    else
+    {
+      char lastBase = base[base.size() - 1];
+      
+      if (lastBase == '/' &&
+          suffix[0] == '/')
+      {
+        return base + suffix.substr(1);
+      }
+      else if (lastBase == '/' ||
+               suffix[0] == '/')
+      {
+        return base + suffix;
+      }
+      else
+      {
+        return base + "/" + suffix;
+      }
+    }
+  }
+
+
   void DicomSource::SetOrthancSource(const Orthanc::WebServiceParameters& parameters)
   {
     type_ = DicomSourceType_Orthanc;
@@ -196,7 +228,7 @@
         std::unique_ptr<HttpCommand> command(new HttpCommand);
         
         command->SetMethod(Orthanc::HttpMethod_Get);
-        command->SetUrl(webService_.GetUrl() + EncodeGetArguments(uri, arguments));
+        command->SetUrl(AddUriSuffix(webService_.GetUrl(), uri + EncodeGetArguments(arguments)));
         command->SetHttpHeaders(webService_.GetHttpHeaders());
 
         for (std::map<std::string, std::string>::const_iterator
@@ -241,7 +273,7 @@
 
         std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
         command->SetMethod(Orthanc::HttpMethod_Post);
-        command->SetUri(orthancDicomWebRoot_ + "/servers/" + serverName_ + "/get");
+        command->SetUri(AddUriSuffix(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get"));
         command->SetBody(body);
 
         if (protection.get())