# HG changeset patch # User Sebastien Jodogne # Date 1357633796 -3600 # Node ID 64925c94825c797303eb05e25842578eeaf32519 # Parent 052dede327617cec47965178a5a888e210afb7e3 api improvement diff -r 052dede32761 -r 64925c94825c Core/HttpServer/EmbeddedResourceHttpHandler.cpp --- 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 #include diff -r 052dede32761 -r 64925c94825c Core/HttpServer/FilesystemHttpHandler.cpp --- 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(""); output.SendString(" "); output.SendString("

Subdirectories

"); diff -r 052dede32761 -r 64925c94825c Core/HttpServer/HttpFileSender.cpp --- 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(GetFileSize()) + "\r\n"; + HttpHandler::Arguments header; + header["Content-Length"] = boost::lexical_cast(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) diff -r 052dede32761 -r 64925c94825c Core/HttpServer/HttpHandler.h --- 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 #include #include -#include "HttpOutput.h" #include "../Toolbox.h" namespace Orthanc { + class HttpOutput; + class HttpHandler { public: diff -r 052dede32761 -r 64925c94825c Core/HttpServer/HttpOutput.cpp --- 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 #include #include #include @@ -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()); } diff -r 052dede32761 -r 64925c94825c Core/HttpServer/HttpOutput.h --- 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 #include #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); diff -r 052dede32761 -r 64925c94825c Core/HttpServer/MongooseServer.cpp --- 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"