changeset 909:ef71057d8b26 plugins

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 20 Jun 2014 13:30:53 +0200
parents e078ea944089
children 28a52982196e
files Core/HttpServer/HttpOutputStream.cpp Core/HttpServer/HttpOutputStream.h Core/HttpServer/MongooseServer.cpp Plugins/Engine/PluginsHttpHandler.cpp
diffstat 4 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutputStream.cpp	Thu Jun 19 17:47:39 2014 +0200
+++ b/Core/HttpServer/HttpOutputStream.cpp	Fri Jun 20 13:30:53 2014 +0200
@@ -53,7 +53,7 @@
       " " + std::string(EnumerationToString(status)) +
       "\r\n";
 
-    SendHeader(&s[0], s.size());
+    Send(true, &s[0], s.size());
   }
 
   void HttpOutputStream::SendHeaderData(const void* buffer, size_t length)
@@ -63,7 +63,7 @@
       throw OrthancException(ErrorCode_BadSequenceOfCalls);
     }
 
-    SendHeader(buffer, length);
+    Send(true, buffer, length);
   }
 
   void HttpOutputStream::SendHeaderString(const std::string& str)
@@ -84,13 +84,13 @@
     if (state_ == State_WritingHeader)
     {
       // Close the HTTP header before writing the body
-      SendHeader("\r\n", 2);
+      Send(true, "\r\n", 2);
       state_ = State_WritingBody;
     }
 
     if (length > 0)
     {
-      SendBody(buffer, length);
+      Send(false, buffer, length);
     }
   }
 
--- a/Core/HttpServer/HttpOutputStream.h	Thu Jun 19 17:47:39 2014 +0200
+++ b/Core/HttpServer/HttpOutputStream.h	Fri Jun 20 13:30:53 2014 +0200
@@ -57,9 +57,7 @@
     {
     }
 
-    virtual void SendHeader(const void* buffer, size_t length) = 0;
-
-    virtual void SendBody(const void* buffer, size_t length) = 0;
+    virtual void Send(bool isHeader, const void* buffer, size_t length) = 0;
 
   public:
     HttpOutputStream() : state_(State_WaitingHttpStatus)
--- a/Core/HttpServer/MongooseServer.cpp	Thu Jun 19 17:47:39 2014 +0200
+++ b/Core/HttpServer/MongooseServer.cpp	Fri Jun 20 13:30:53 2014 +0200
@@ -74,7 +74,7 @@
       struct mg_connection* connection_;
 
     protected:
-      virtual void SendBody(const void* buffer, size_t length)
+      virtual void Send(bool isHeader, const void* buffer, size_t length)
       {
         if (length > 0)
         {
@@ -82,11 +82,6 @@
         }
       }
 
-      virtual void SendHeader(const void* buffer, size_t length)
-      {
-        SendBody(buffer, length);
-      }
-
     public:
       MongooseOutputStream(struct mg_connection* connection) : connection_(connection)
       {
--- a/Plugins/Engine/PluginsHttpHandler.cpp	Thu Jun 19 17:47:39 2014 +0200
+++ b/Plugins/Engine/PluginsHttpHandler.cpp	Fri Jun 20 13:30:53 2014 +0200
@@ -56,12 +56,13 @@
         return target_;
       }
 
-      virtual void SendHeaderData(const void* buffer, size_t length)
+      virtual void Send(bool isHeader, const void* buffer, size_t length)
       {
-      }
+        if (isHeader)
+        {
+          return;
+        }
 
-      virtual void SendBodyData(const void* buffer, size_t length)
-      {
         size_t pos = target_.size();
         target_.resize(pos + length);