# HG changeset patch # User Sebastien Jodogne # Date 1466794153 -7200 # Node ID b534834a300e2dec90a22f086276e7b4c8ae89e3 # Parent 21a8ca9ad928b85da077bd59d34a96e0a741aef2 fix diff -r 21a8ca9ad928 -r b534834a300e Core/HttpServer/StringHttpOutput.cpp --- a/Core/HttpServer/StringHttpOutput.cpp Fri Jun 24 11:42:23 2016 +0200 +++ b/Core/HttpServer/StringHttpOutput.cpp Fri Jun 24 20:49:13 2016 +0200 @@ -39,10 +39,18 @@ { void StringHttpOutput::OnHttpStatusReceived(HttpStatus status) { - if (status != HttpStatus_200_Ok && - status != HttpStatus_404_NotFound) + switch (status) { - throw OrthancException(ErrorCode_BadRequest); + case HttpStatus_200_Ok: + found_ = true; + break; + + case HttpStatus_404_NotFound: + found_ = false; + break; + + default: + throw OrthancException(ErrorCode_BadRequest); } } @@ -53,4 +61,16 @@ buffer_.AddChunk(reinterpret_cast(buffer), length); } } + + void StringHttpOutput::GetOutput(std::string& output) + { + if (found_) + { + buffer_.Flatten(output); + } + else + { + throw OrthancException(ErrorCode_UnknownResource); + } + } } diff -r 21a8ca9ad928 -r b534834a300e Core/HttpServer/StringHttpOutput.h --- a/Core/HttpServer/StringHttpOutput.h Fri Jun 24 11:42:23 2016 +0200 +++ b/Core/HttpServer/StringHttpOutput.h Fri Jun 24 20:49:13 2016 +0200 @@ -41,16 +41,18 @@ class StringHttpOutput : public IHttpOutputStream { private: + bool found_; ChunkedBuffer buffer_; public: + StringHttpOutput() : found_(false) + { + } + virtual void OnHttpStatusReceived(HttpStatus status); virtual void Send(bool isHeader, const void* buffer, size_t length); - void GetOutput(std::string& output) - { - buffer_.Flatten(output); - } + void GetOutput(std::string& output); }; }