changeset 324:64925c94825c

api improvement
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jan 2013 09:29:56 +0100
parents 052dede32761
children 71d30b9ce801
files Core/HttpServer/EmbeddedResourceHttpHandler.cpp Core/HttpServer/FilesystemHttpHandler.cpp Core/HttpServer/HttpFileSender.cpp Core/HttpServer/HttpHandler.h Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpOutput.h Core/HttpServer/MongooseServer.cpp
diffstat 7 files changed, 27 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpServer/EmbeddedResourceHttpHandler.cpp	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/EmbeddedResourceHttpHandler.cpp	Tue Jan 08 09:29:56 2013 +0100
@@ -33,6 +33,7 @@
 #include "EmbeddedResourceHttpHandler.h"
 
 #include "../OrthancException.h"
+#include "HttpOutput.h"
 
 #include <stdio.h>
 #include <glog/logging.h>
--- a/Core/HttpServer/FilesystemHttpHandler.cpp	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/FilesystemHttpHandler.cpp	Tue Jan 08 09:29:56 2013 +0100
@@ -54,7 +54,10 @@
   {
     namespace fs = boost::filesystem;
 
-    output.SendCustomOkHeader("Content-Type: text/html\r\n");
+    HttpHandler::Arguments header;
+    header["Content-Type"] = "text/html";
+    output.SendOkHeader(header);
+
     output.SendString("<html>");
     output.SendString("  <body>");
     output.SendString("    <h1>Subdirectories</h1>");
--- a/Core/HttpServer/HttpFileSender.cpp	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/HttpFileSender.cpp	Tue Jan 08 09:29:56 2013 +0100
@@ -38,20 +38,20 @@
 {
   void HttpFileSender::SendHeader(HttpOutput& output)
   {
-    std::string header;
-    header += "Content-Length: " + boost::lexical_cast<std::string>(GetFileSize()) + "\r\n";
+    HttpHandler::Arguments header;
+    header["Content-Length"] = boost::lexical_cast<std::string>(GetFileSize());
 
     if (contentType_.size() > 0)
     {
-      header += "Content-Type: " + contentType_ + "\r\n";
+      header["Content-Type"] = contentType_;
     }
 
     if (downloadFilename_.size() > 0)
     {
-      header += "Content-Disposition: attachment; filename=\"" + downloadFilename_ + "\"\r\n";
+      header["Content-Disposition"] = "attachment; filename=\"" + downloadFilename_ + "\"";
     }
   
-    output.SendCustomOkHeader(header);
+    output.SendOkHeader(header);
   }
 
   void HttpFileSender::Send(HttpOutput& output)
--- a/Core/HttpServer/HttpHandler.h	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/HttpHandler.h	Tue Jan 08 09:29:56 2013 +0100
@@ -35,11 +35,12 @@
 #include <map>
 #include <vector>
 #include <stdint.h>
-#include "HttpOutput.h"
 #include "../Toolbox.h"
 
 namespace Orthanc
 {
+  class HttpOutput;
+
   class HttpHandler
   {
   public:
--- a/Core/HttpServer/HttpOutput.cpp	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/HttpOutput.cpp	Tue Jan 08 09:29:56 2013 +0100
@@ -32,6 +32,7 @@
 
 #include "HttpOutput.h"
 
+#include <iostream>
 #include <vector>
 #include <stdio.h>
 #include <boost/lexical_cast.hpp>
@@ -76,10 +77,18 @@
     Send(&s[0], s.size());
   }
 
+  void HttpOutput::SendOkHeader(const HttpHandler::Arguments& header)
+  {
+    std::string s = "HTTP/1.1 200 OK\r\n";
 
-  void HttpOutput::SendCustomOkHeader(const std::string& customHeader)
-  {
-    std::string s = "HTTP/1.1 200 OK\r\n" + customHeader + "\r\n";
+    for (HttpHandler::Arguments::const_iterator 
+           it = header.begin(); it != header.end(); it++)
+    {
+      s += it->first + ": " + it->second + "\r\n";
+    }
+
+    s += "\r\n";
+
     Send(&s[0], s.size());
   }
 
--- a/Core/HttpServer/HttpOutput.h	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/HttpOutput.h	Tue Jan 08 09:29:56 2013 +0100
@@ -35,6 +35,7 @@
 #include <string>
 #include <stdint.h>
 #include "../Enumerations.h"
+#include "HttpHandler.h"
 
 namespace Orthanc
 {
@@ -55,7 +56,7 @@
                       uint64_t contentLength,
                       const char* contentFilename);
 
-    void SendCustomOkHeader(const std::string& customHeader);
+    void SendOkHeader(const HttpHandler::Arguments& header);
 
     void SendString(const std::string& s);
 
--- a/Core/HttpServer/MongooseServer.cpp	Mon Jan 07 16:48:35 2013 +0100
+++ b/Core/HttpServer/MongooseServer.cpp	Tue Jan 08 09:29:56 2013 +0100
@@ -46,6 +46,7 @@
 
 #include "../OrthancException.h"
 #include "../ChunkedBuffer.h"
+#include "HttpOutput.h"
 #include "mongoose.h"