changeset 238:11d05a138412

Improved WADO-RS compatibility if Orthanc is acting as a DICOMweb client
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Nov 2018 16:31:08 +0100 (2018-11-08)
parents 78f0557d70ee
children f1d1dd716eaa
files NEWS Plugin/DicomWebClient.cpp
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Wed Nov 07 14:46:43 2018 +0100
+++ b/NEWS	Thu Nov 08 16:31:08 2018 +0100
@@ -2,6 +2,7 @@
 ===============================
 
 * Sending "HttpHeaders" of the "DicomWeb.Servers" configuration to remote DICOMweb servers
+* Improved WADO-RS compatibility if Orthanc is acting as a DICOMweb client
 
 
 Version 0.5 (2018-04-19)
--- a/Plugin/DicomWebClient.cpp	Wed Nov 07 14:46:43 2018 +0100
+++ b/Plugin/DicomWebClient.cpp	Thu Nov 08 16:31:08 2018 +0100
@@ -477,6 +477,7 @@
   std::map<std::string, std::string> answerHeaders;
   OrthancPlugins::CallServer(answerBody, answerHeaders, server, OrthancPluginHttpMethod_Get, httpHeaders, uri, "");
 
+  std::string contentTypeFull;
   std::vector<std::string> contentType;
   for (std::map<std::string, std::string>::const_iterator 
          it = answerHeaders.begin(); it != answerHeaders.end(); ++it)
@@ -485,11 +486,15 @@
     Orthanc::Toolbox::ToLowerCase(s);
     if (s == "content-type")
     {
+      contentTypeFull = it->second;
       Orthanc::Toolbox::TokenizeString(contentType, it->second, ';');
       break;
     }
   }
 
+  OrthancPlugins::Configuration::LogInfo("Got " + boost::lexical_cast<std::string>(answerBody.GetSize()) +
+                                         " bytes from a WADO-RS query with content type: " + contentTypeFull);
+  
   if (contentType.empty())
   {
     OrthancPlugins::Configuration::LogError("No Content-Type provided by the remote WADO-RS server");
@@ -539,6 +544,17 @@
     }
   }
 
+  // Strip the trailing and heading quotes if present
+  if (boundary.length() > 2 &&
+      boundary.front() == '"' &&
+      boundary.back() == '"')
+  {
+    boundary = boundary.substr(1, boundary.size() - 2);
+  }
+
+  OrthancPlugins::Configuration::LogInfo("  Parsing the multipart content type: " + type +
+                                         " with boundary: " + boundary);
+
   if (type != APPLICATION_DICOM)
   {
     OrthancPlugins::Configuration::LogError("The remote WADO-RS server answers with a \"" + type +
@@ -563,9 +579,20 @@
 
   for (size_t i = 0; i < parts.size(); i++)
   {
-    if (parts[i].contentType_ != APPLICATION_DICOM)
+    std::vector<std::string> tokens;
+    Orthanc::Toolbox::TokenizeString(tokens, parts[i].contentType_, ';');
+
+    std::string partType;
+    if (tokens.size() > 0)
     {
-      OrthancPlugins::Configuration::LogError("The remote WADO-RS server has provided a non-DICOM file in its multipart answer");
+      partType = Orthanc::Toolbox::StripSpaces(tokens[0]);
+    }
+
+    if (partType != APPLICATION_DICOM)
+    {
+      OrthancPlugins::Configuration::LogError(
+        "The remote WADO-RS server has provided a non-DICOM file in its multipart answer"
+        " (content type: " + parts[i].contentType_ + ")");
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);      
     }