changeset 1592:d73124f6b439

configuration option HttpDescribeErrors
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Aug 2015 11:35:16 +0200
parents cd9d99fe32e9
children 235d89817b89
files Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpOutput.h Core/HttpServer/MongooseServer.cpp Core/HttpServer/MongooseServer.h NEWS OrthancServer/OrthancInitialization.cpp OrthancServer/main.cpp Resources/Configuration.json
diffstat 8 files changed, 102 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Thu Aug 27 10:54:52 2015 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Thu Aug 27 11:35:16 2015 +0200
@@ -302,7 +302,15 @@
     
     stateMachine_.ClearHeaders();
     stateMachine_.SetHttpStatus(status);
-    stateMachine_.SendBody(message, messageSize);
+
+    if (describeErrors_)
+    {
+      stateMachine_.SendBody(message, messageSize);
+    }
+    else
+    {
+      stateMachine_.SendBody(NULL, 0);
+    }
   }
 
 
--- a/Core/HttpServer/HttpOutput.h	Thu Aug 27 10:54:52 2015 +0200
+++ b/Core/HttpServer/HttpOutput.h	Thu Aug 27 11:35:16 2015 +0200
@@ -114,6 +114,7 @@
     StateMachine stateMachine_;
     bool         isDeflateAllowed_;
     bool         isGzipAllowed_;
+    bool         describeErrors_;
 
     HttpCompression GetPreferredCompression(size_t bodySize) const;
 
@@ -122,7 +123,8 @@
                bool isKeepAlive) : 
       stateMachine_(stream, isKeepAlive),
       isDeflateAllowed_(false),
-      isGzipAllowed_(false)
+      isGzipAllowed_(false),
+      describeErrors_(true)
     {
     }
 
@@ -146,6 +148,16 @@
       return isGzipAllowed_;
     }
 
+    void SetDescribeErrorsEnabled(bool enabled)
+    {
+      describeErrors_ = enabled;
+    }
+
+    bool IsDescribeErrorsEnabled() const
+    {
+      return describeErrors_;      
+    }
+
     void SendStatus(HttpStatus status,
 		    const char* message,
 		    size_t messageSize);
--- a/Core/HttpServer/MongooseServer.cpp	Thu Aug 27 10:54:52 2015 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Thu Aug 27 11:35:16 2015 +0200
@@ -583,6 +583,7 @@
 
     MongooseOutputStream stream(connection);
     HttpOutput output(stream, that->IsKeepAliveEnabled());
+    output.SetDescribeErrorsEnabled(that->IsDescribeErrorsEnabled());
 
     // Check remote calls
     if (!that->IsRemoteAccessAllowed() &&
@@ -831,6 +832,7 @@
     filter_ = NULL;
     keepAlive_ = false;
     httpCompression_ = true;
+    describeErrors_ = true;
 
 #if ORTHANC_SSL_ENABLED == 1
     // Check for the Heartbleed exploit
@@ -980,6 +982,12 @@
     httpCompression_ = enabled;
     LOG(WARNING) << "HTTP compression is " << (enabled ? "enabled" : "disabled");
   }
+  
+  void MongooseServer::SetDescribeErrorsEnabled(bool enabled)
+  {
+    describeErrors_ = enabled;
+    LOG(INFO) << "Description of the errors in the HTTP answers is " << (enabled ? "enabled" : "disabled");
+  }
 
   void MongooseServer::SetIncomingHttpRequestFilter(IIncomingHttpRequestFilter& filter)
   {
--- a/Core/HttpServer/MongooseServer.h	Thu Aug 27 10:54:52 2015 +0200
+++ b/Core/HttpServer/MongooseServer.h	Thu Aug 27 11:35:16 2015 +0200
@@ -77,6 +77,7 @@
     IIncomingHttpRequestFilter* filter_;
     bool keepAlive_;
     bool httpCompression_;
+    bool describeErrors_;
   
     bool IsRunning() const;
 
@@ -143,6 +144,13 @@
 
     void SetHttpCompressionEnabled(bool enabled);
 
+    bool IsDescribeErrorsEnabled() const
+    {
+      return describeErrors_;
+    }
+
+    void SetDescribeErrorsEnabled(bool enabled);
+
     const IIncomingHttpRequestFilter* GetIncomingHttpRequestFilter() const
     {
       return filter_;
--- a/NEWS	Thu Aug 27 10:54:52 2015 +0200
+++ b/NEWS	Thu Aug 27 11:35:16 2015 +0200
@@ -31,6 +31,7 @@
 * Improved error codes
 * Many code refactorings
 * If error while calling the REST API, the answer body contains an error description
+  (this feature can be disabled with the "HttpDescribeErrors" option)
 * Upgrade to curl 7.44.0 for static and Windows builds
 * Upgrade to libcurl 1.0.2d for static and Windows builds
 * Bypass zlib uncompression if "StorageCompression" is enabled and HTTP client supports deflate
--- a/OrthancServer/OrthancInitialization.cpp	Thu Aug 27 10:54:52 2015 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Thu Aug 27 11:35:16 2015 +0200
@@ -82,7 +82,15 @@
   {
     if (configuration_.isMember(parameter))
     {
-      return configuration_[parameter].asString();
+      if (configuration_[parameter].type() != Json::stringValue)
+      {
+        LOG(ERROR) << "The configuration option \"" << parameter << "\" must be a string";
+        throw OrthancException(ErrorCode_BadParameterType);
+      }
+      else
+      {
+        return configuration_[parameter].asString();
+      }
     }
     else
     {
@@ -96,7 +104,15 @@
   {
     if (configuration_.isMember(parameter))
     {
-      return configuration_[parameter].asBool();
+      if (configuration_[parameter].type() != Json::booleanValue)
+      {
+        LOG(ERROR) << "The configuration option \"" << parameter << "\" must be a Boolean (true or false)";
+        throw OrthancException(ErrorCode_BadParameterType);
+      }
+      else
+      {
+        return configuration_[parameter].asBool();
+      }
     }
     else
     {
@@ -382,7 +398,15 @@
 
     if (configuration_.isMember(parameter))
     {
-      return configuration_[parameter].asInt();
+      if (configuration_[parameter].type() != Json::intValue)
+      {
+        LOG(ERROR) << "The configuration option \"" << parameter << "\" must be an integer";
+        throw OrthancException(ErrorCode_BadParameterType);
+      }
+      else
+      {
+        return configuration_[parameter].asInt();
+      }
     }
     else
     {
--- a/OrthancServer/main.cpp	Thu Aug 27 10:54:52 2015 +0200
+++ b/OrthancServer/main.cpp	Thu Aug 27 11:35:16 2015 +0200
@@ -423,6 +423,7 @@
   httpServer.SetRemoteAccessAllowed(Configuration::GetGlobalBoolParameter("RemoteAccessAllowed", false));
   httpServer.SetKeepAliveEnabled(Configuration::GetGlobalBoolParameter("KeepAlive", false));
   httpServer.SetHttpCompressionEnabled(Configuration::GetGlobalBoolParameter("HttpCompressionEnabled", true));
+  httpServer.SetDescribeErrorsEnabled(Configuration::GetGlobalBoolParameter("HttpDescribeErrors", true));
   httpServer.SetIncomingHttpRequestFilter(httpFilter);
 
   httpServer.SetAuthenticationEnabled(Configuration::GetGlobalBoolParameter("AuthenticationEnabled", false));
--- a/Resources/Configuration.json	Thu Aug 27 10:54:52 2015 +0200
+++ b/Resources/Configuration.json	Thu Aug 27 11:35:16 2015 +0200
@@ -42,19 +42,41 @@
   ],
 
 
+
   /**
    * Configuration of the HTTP server
    **/
 
+  // Enable the HTTP server. If this parameter is set to "false",
+  // Orthanc acts as a pure DICOM server. The REST API and Orthanc
+  // Explorer will not be available.
+  "HttpServerEnabled" : true,
+
   // HTTP port for the REST services and for the GUI
   "HttpPort" : 8042,
 
+  // When the following option is "true", if an error is encountered
+  // while calling the REST API, a JSON message describing the error
+  // is put in the HTTP answer. This feature can be disabled if the
+  // HTTP client does not properly handles such answers.
+  "HttpDescribeErrors" : true,
+
+  // Enable HTTP compression to improve network bandwidth utilization,
+  // at the expense of more computations on the server. Orthanc
+  // supports the "gzip" and "deflate" HTTP encodings.
+  "HttpCompressionEnabled" : true,
+
 
 
   /**
    * Configuration of the DICOM server
    **/
 
+  // Enable the DICOM server. If this parameter is set to "false",
+  // Orthanc acts as a pure REST server. It will not be possible to
+  // receive files or to do query/retrieve through the DICOM protocol.
+  "DicomServerEnabled" : true,
+
   // The DICOM Application Entity Title
   "DicomAet" : "ORTHANC",
 
@@ -81,6 +103,7 @@
   "RleTransferSyntaxAccepted"          : true,
 
 
+
   /**
    * Security-related options for the HTTP server
    **/
@@ -149,6 +172,17 @@
   // Set the timeout for HTTP requests issued by Orthanc (in seconds).
   "HttpTimeout" : 10,
 
+  // Enable the verification of the peers during HTTPS requests.
+  // Reference: http://curl.haxx.se/docs/sslcerts.html
+  "HttpsVerifyPeers" : true,
+
+  // Path to the CA (certification authority) certificates to validate
+  // peers in HTTPS requests. From curl documentation ("--cacert"
+  // option): "Tells curl to use the specified certificate file to
+  // verify the peers. The file may contain multiple CA
+  // certificates. The certificate(s) must be in PEM format."
+  "HttpsCACertificates" : "",
+
 
 
   /**
@@ -173,16 +207,6 @@
   // patient, a study or a series is considered as stable.
   "StableAge" : 60,
 
-  // Enable the HTTP server. If this parameter is set to "false",
-  // Orthanc acts as a pure DICOM server. The REST API and Orthanc
-  // Explorer will not be available.
-  "HttpServerEnabled" : true,
-
-  // Enable the DICOM server. If this parameter is set to "false",
-  // Orthanc acts as a pure REST server. It will not be possible to
-  // receive files or to do query/retrieve through the DICOM protocol.
-  "DicomServerEnabled" : true,
-
   // By default, Orthanc compares AET (Application Entity Titles) in a
   // case-insensitive way. Setting this option to "true" will enable
   // case-sensitive matching.
@@ -236,21 +260,5 @@
   // When handling a C-Find SCP request, setting this flag to "false"
   // will enable case-insensitive match for PN value representation
   // (such as PatientName). By default, the search is case-insensitive.
-  "CaseSensitivePN" : false,
-
-  // Enable HTTP compression to improve network bandwidth utilization,
-  // at the expense of more computations on the server. Orthanc
-  // supports the "gzip" and "deflate" encodings.
-  "HttpCompressionEnabled" : true,
-
-  // Enable the verification of the peers during HTTPS requests.
-  // Reference: http://curl.haxx.se/docs/sslcerts.html
-  "HttpsVerifyPeers" : true,
-
-  // Path to the CA (certification authority) certificates to validate
-  // peers in HTTPS requests. From curl documentation ("--cacert"
-  // option): "Tells curl to use the specified certificate file to
-  // verify the peers. The file may contain multiple CA
-  // certificates. The certificate(s) must be in PEM format."
-  "HttpsCACertificates" : ""
+  "CaseSensitivePN" : false
 }