diff OrthancStone/Sources/Loaders/DicomSource.cpp @ 2153:32bfccdc030f

consistency in the way URLs are concatenated
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Sep 2024 18:09:24 +0200
parents 16c01cc201e7
children
line wrap: on
line diff
--- a/OrthancStone/Sources/Loaders/DicomSource.cpp	Sat Aug 31 08:37:39 2024 +0200
+++ b/OrthancStone/Sources/Loaders/DicomSource.cpp	Wed Sep 25 18:09:24 2024 +0200
@@ -25,6 +25,7 @@
 
 #include "../Oracle/HttpCommand.h"
 #include "../Oracle/OrthancRestApiCommand.h"
+#include "../Toolbox/StoneToolbox.h"
 
 #include <OrthancException.h>
 #include <Toolbox.h>
@@ -60,39 +61,6 @@
   }
 
 
-  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;
@@ -229,7 +197,7 @@
         std::unique_ptr<HttpCommand> command(new HttpCommand);
         
         command->SetMethod(Orthanc::HttpMethod_Get);
-        command->SetUrl(AddUriSuffix(webService_.GetUrl(), uri + EncodeGetArguments(arguments)));
+        command->SetUrl(StoneToolbox::JoinUrl(webService_.GetUrl(), uri + EncodeGetArguments(arguments)));
         command->SetHttpHeaders(webService_.GetHttpHeaders());
 
         for (std::map<std::string, std::string>::const_iterator
@@ -274,7 +242,7 @@
 
         std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
         command->SetMethod(Orthanc::HttpMethod_Post);
-        command->SetUri(AddUriSuffix(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get"));
+        command->SetUri(StoneToolbox::JoinUrl(orthancDicomWebRoot_, "/servers/" + serverName_ + "/get"));
         command->SetBody(body);
 
         if (protection.get())