# HG changeset patch # User Sebastien Jodogne # Date 1358345694 -3600 # Node ID 639272ef761572a5950b3ba8aea946a3fbf4f305 # Parent 3a3b3ba8c1e0b6016fa698a82ca74e99f5a80d7e answer raw buffers diff -r 3a3b3ba8c1e0 -r 639272ef7615 Core/HttpServer/HttpOutput.cpp --- a/Core/HttpServer/HttpOutput.cpp Mon Jan 14 11:35:01 2013 +0100 +++ b/Core/HttpServer/HttpOutput.cpp Wed Jan 16 15:14:54 2013 +0100 @@ -141,19 +141,24 @@ } + 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); - - for (HttpHandler::Arguments::const_iterator it = cookies.begin(); - it != cookies.end(); it++) - { - header.push_back(std::make_pair("Set-Cookie", it->first + "=" + it->second)); - } - + PrepareCookies(header, cookies); SendOkHeader(header); SendString(buffer); } @@ -167,6 +172,21 @@ Send(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); + Send(buffer, size); + } + + + void HttpOutput::Redirect(const std::string& path) { std::string s = diff -r 3a3b3ba8c1e0 -r 639272ef7615 Core/HttpServer/HttpOutput.h --- a/Core/HttpServer/HttpOutput.h Mon Jan 14 11:35:01 2013 +0100 +++ b/Core/HttpServer/HttpOutput.h Wed Jan 16 15:14:54 2013 +0100 @@ -55,6 +55,9 @@ void SendOkHeader(const Header& header); + void PrepareCookies(Header& header, + const HttpHandler::Arguments& cookies); + public: virtual ~HttpOutput() { @@ -87,5 +90,10 @@ void AnswerBufferWithContentType(const void* buffer, size_t size, const std::string& contentType); + + void AnswerBufferWithContentType(const void* buffer, + size_t size, + const std::string& contentType, + const HttpHandler::Arguments& cookies); }; } diff -r 3a3b3ba8c1e0 -r 639272ef7615 Core/RestApi/RestApiOutput.cpp --- a/Core/RestApi/RestApiOutput.cpp Mon Jan 14 11:35:01 2013 +0100 +++ b/Core/RestApi/RestApiOutput.cpp Wed Jan 16 15:14:54 2013 +0100 @@ -84,6 +84,15 @@ alreadySent_ = true; } + void RestApiOutput::AnswerBuffer(const void* buffer, + size_t length, + const std::string& contentType) + { + CheckStatus(); + output_.AnswerBufferWithContentType(buffer, length, contentType, cookies_); + alreadySent_ = true; + } + void RestApiOutput::Redirect(const std::string& path) { CheckStatus(); diff -r 3a3b3ba8c1e0 -r 639272ef7615 Core/RestApi/RestApiOutput.h --- a/Core/RestApi/RestApiOutput.h Mon Jan 14 11:35:01 2013 +0100 +++ b/Core/RestApi/RestApiOutput.h Wed Jan 16 15:14:54 2013 +0100 @@ -70,6 +70,10 @@ void AnswerBuffer(const std::string& buffer, const std::string& contentType); + void AnswerBuffer(const void* buffer, + size_t length, + const std::string& contentType); + void SignalError(Orthanc_HttpStatus status); void Redirect(const std::string& path);