diff Core/HttpServer/HttpOutput.cpp @ 1042:8d1845feb277

set cookies, not allowed methods, unauthorized in plugins
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 17 Jul 2014 15:55:40 +0200
parents 306afd58a0b3
children ba5c0908600c
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp	Thu Jul 17 14:14:15 2014 +0200
+++ b/Core/HttpServer/HttpOutput.cpp	Thu Jul 17 15:55:40 2014 +0200
@@ -36,6 +36,7 @@
 #include <iostream>
 #include <vector>
 #include <stdio.h>
+#include <glog/logging.h>
 #include <boost/lexical_cast.hpp>
 #include "../OrthancException.h"
 #include "../Toolbox.h"
@@ -46,7 +47,8 @@
   {
     if (state_ != State_WaitingHttpStatus)
     {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+      LOG(ERROR) << "Sending twice an HTTP status";
+      return;
     }
 
     stream_.OnHttpStatusReceived(status);
@@ -153,11 +155,17 @@
       s += it->first + ": " + it->second + "\r\n";
     }
 
+    for (HttpHandler::Arguments::const_iterator 
+           it = cookies_.begin(); it != cookies_.end(); ++it)
+    {
+      s += "Set-Cookie: " + it->first + "=" + it->second + "\r\n";
+    }
+
     stateMachine_.SendHeaderString(s);
   }
 
 
-  void HttpOutput::SendMethodNotAllowedError(const std::string& allowed)
+  void HttpOutput::SendMethodNotAllowed(const std::string& allowed)
   {
     stateMachine_.SendHttpStatus(HttpStatus_405_MethodNotAllowed);
     stateMachine_.SendHeaderString("Allow: " + allowed + "\r\n");
@@ -181,29 +189,8 @@
   void HttpOutput::AnswerBufferWithContentType(const std::string& buffer,
                                                const std::string& contentType)
   {
-    SendOkHeader(contentType.c_str(), true, buffer.size(), NULL);
-    SendBodyString(buffer);
-  }
-
-
-  void HttpOutput::PrepareCookies(Header& header,
-                                  const HttpHandler::Arguments& cookies)
-  {
-    for (HttpHandler::Arguments::const_iterator it = cookies.begin();
-         it != cookies.end(); ++it)
-    {
-      header.push_back(std::make_pair("Set-Cookie", it->first + "=" + it->second));
-    }
-  }
-
-
-  void HttpOutput::AnswerBufferWithContentType(const std::string& buffer,
-                                               const std::string& contentType,
-                                               const HttpHandler::Arguments& cookies)
-  {
     Header header;
     PrepareOkHeader(header, contentType.c_str(), true, buffer.size(), NULL);
-    PrepareCookies(header, cookies);
     SendOkHeader(header);
     SendBodyString(buffer);
   }
@@ -213,19 +200,8 @@
                                                size_t size,
                                                const std::string& contentType)
   {
-    SendOkHeader(contentType.c_str(), true, size, NULL);
-    SendBodyData(buffer, size);
-  }
-
-
-  void HttpOutput::AnswerBufferWithContentType(const void* buffer,
-                                               size_t size,
-                                               const std::string& contentType,
-                                               const HttpHandler::Arguments& cookies)
-  {
     Header header;
     PrepareOkHeader(header, contentType.c_str(), true, size, NULL);
-    PrepareCookies(header, cookies);
     SendOkHeader(header);
     SendBodyData(buffer, size);
   }