changeset 2046:b534834a300e

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 24 Jun 2016 20:49:13 +0200
parents 21a8ca9ad928
children 438f86ee19fc
files Core/HttpServer/StringHttpOutput.cpp Core/HttpServer/StringHttpOutput.h
diffstat 2 files changed, 29 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/StringHttpOutput.cpp	Fri Jun 24 11:42:23 2016 +0200
+++ b/Core/HttpServer/StringHttpOutput.cpp	Fri Jun 24 20:49:13 2016 +0200
@@ -39,10 +39,18 @@
 {
   void StringHttpOutput::OnHttpStatusReceived(HttpStatus status)
   {
-    if (status != HttpStatus_200_Ok &&
-        status != HttpStatus_404_NotFound)
+    switch (status)
     {
-      throw OrthancException(ErrorCode_BadRequest);
+      case HttpStatus_200_Ok:
+        found_ = true;
+        break;
+
+      case HttpStatus_404_NotFound:
+        found_ = false;
+        break;
+
+      default:
+        throw OrthancException(ErrorCode_BadRequest);
     }
   }
 
@@ -53,4 +61,16 @@
       buffer_.AddChunk(reinterpret_cast<const char*>(buffer), length);
     }
   }
+
+  void StringHttpOutput::GetOutput(std::string& output)
+  {
+    if (found_)
+    {
+      buffer_.Flatten(output);
+    }
+    else
+    {
+      throw OrthancException(ErrorCode_UnknownResource);
+    }
+  }
 }
--- a/Core/HttpServer/StringHttpOutput.h	Fri Jun 24 11:42:23 2016 +0200
+++ b/Core/HttpServer/StringHttpOutput.h	Fri Jun 24 20:49:13 2016 +0200
@@ -41,16 +41,18 @@
   class StringHttpOutput : public IHttpOutputStream
   {
   private:
+    bool          found_;
     ChunkedBuffer buffer_;
 
   public:
+    StringHttpOutput() : found_(false)
+    {
+    }
+
     virtual void OnHttpStatusReceived(HttpStatus status);
 
     virtual void Send(bool isHeader, const void* buffer, size_t length);
 
-    void GetOutput(std::string& output)
-    {
-      buffer_.Flatten(output);
-    }
+    void GetOutput(std::string& output);
   };
 }