diff Core/RestApi/RestApiOutput.cpp @ 210:96b7918a6a18

start of the refactoring of the Orthanc REST API
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 28 Nov 2012 18:03:44 +0100
parents 9960642f0f45
children b7aea293b965
line wrap: on
line diff
--- a/Core/RestApi/RestApiOutput.cpp	Wed Nov 28 17:22:07 2012 +0100
+++ b/Core/RestApi/RestApiOutput.cpp	Wed Nov 28 18:03:44 2012 +0100
@@ -34,9 +34,25 @@
 
 namespace Orthanc
 {
+  RestApiOutput::RestApiOutput(HttpOutput& output) : 
+    output_(output)
+  {
+    existingResource_ = false;
+  }
+
+
+  RestApiOutput::~RestApiOutput()
+  {
+    if (!existingResource_)
+    {
+      output_.SendHeader(Orthanc_HttpStatus_400_BadRequest);
+    }
+  }
+
   void RestApiOutput::AnswerFile(HttpFileSender& sender)
   {
     sender.Send(output_);
+    existingResource_ = true;
   }
 
   void RestApiOutput::AnswerJson(const Json::Value& value)
@@ -44,16 +60,19 @@
     Json::StyledWriter writer;
     std::string s = writer.write(value);
     output_.AnswerBufferWithContentType(s, "application/json");
+    existingResource_ = true;
   }
 
   void RestApiOutput::AnswerBuffer(const std::string& buffer,
                                    const std::string& contentType)
   {
     output_.AnswerBufferWithContentType(buffer, contentType);
+    existingResource_ = true;
   }
 
   void RestApiOutput::Redirect(const char* path)
   {
     output_.Redirect(path);
+    existingResource_ = true;
   }
 }