diff Core/HttpServer/HttpOutput.h @ 908:e078ea944089 plugins

refactoring HttpOutput
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jun 2014 17:47:39 +0200
parents 2d0a347e8cfc
children 28a52982196e
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.h	Thu Jun 19 14:28:43 2014 +0200
+++ b/Core/HttpServer/HttpOutput.h	Thu Jun 19 17:47:39 2014 +0200
@@ -36,6 +36,7 @@
 #include <string>
 #include <stdint.h>
 #include "../Enumerations.h"
+#include "HttpOutputStream.h"
 #include "HttpHandler.h"
 
 namespace Orthanc
@@ -45,8 +46,6 @@
   private:
     typedef std::list< std::pair<std::string, std::string> >  Header;
 
-    void SendHeaderInternal(HttpStatus status);
-
     void PrepareOkHeader(Header& header,
                          const char* contentType,
                          bool hasContentLength,
@@ -58,19 +57,27 @@
     void PrepareCookies(Header& header,
                         const HttpHandler::Arguments& cookies);
 
+    HttpOutputStream& stream_;
+
   public:
-    virtual ~HttpOutput()
+    HttpOutput(HttpOutputStream& stream) : stream_(stream)
     {
     }
 
-    virtual void Send(const void* buffer, size_t length) = 0;
-
     void SendOkHeader(const char* contentType,
                       bool hasContentLength,
                       uint64_t contentLength,
                       const char* contentFilename);
 
-    void SendString(const std::string& s);
+    void SendBodyData(const void* buffer, size_t length)
+    {
+      stream_.SendBodyData(buffer, length);
+    }
+
+    void SendBodyString(const std::string& str)
+    {
+      stream_.SendBodyString(str);
+    }
 
     void SendMethodNotAllowedError(const std::string& allowed);
 
@@ -78,6 +85,8 @@
 
     void Redirect(const std::string& path);
 
+    void SendUnauthorized(const std::string& realm);
+
     // Higher-level constructs to send entire buffers ----------------------------
 
     void AnswerBufferWithContentType(const std::string& buffer,