Mercurial > hg > orthanc
changeset 339:639272ef7615
answer raw buffers
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 16 Jan 2013 15:14:54 +0100 |
parents | 3a3b3ba8c1e0 |
children | 61f6a3d66b85 |
files | Core/HttpServer/HttpOutput.cpp Core/HttpServer/HttpOutput.h Core/RestApi/RestApiOutput.cpp Core/RestApi/RestApiOutput.h |
diffstat | 4 files changed, 48 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- 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 =
--- 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); }; }
--- 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();
--- 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);