Mercurial > hg > orthanc
diff Core/RestApi/RestApiOutput.cpp @ 1113:ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Sep 2014 15:51:20 +0200 |
parents | f21f7783f934 |
children | 0561f2087cc9 |
line wrap: on
line diff
--- a/Core/RestApi/RestApiOutput.cpp Mon Sep 01 12:20:26 2014 +0200 +++ b/Core/RestApi/RestApiOutput.cpp Tue Sep 02 15:51:20 2014 +0200 @@ -50,6 +50,14 @@ RestApiOutput::~RestApiOutput() { } + + void RestApiOutput::Finalize() + { + if (!alreadySent_) + { + output_.SendStatus(HttpStatus_404_NotFound); + } + } void RestApiOutput::CheckStatus() { @@ -75,7 +83,8 @@ #if ORTHANC_PUGIXML_ENABLED == 1 std::string s; Toolbox::JsonToXml(s, value); - output_.AnswerBufferWithContentType(s, "application/xml"); + output_.SetContentType("application/xml"); + output_.SendBody(s); #else LOG(ERROR) << "Orthanc was compiled without XML support"; throw OrthancException(ErrorCode_InternalError); @@ -84,8 +93,8 @@ else { Json::StyledWriter writer; - std::string s = writer.write(value); - output_.AnswerBufferWithContentType(s, "application/json"); + output_.SetContentType("application/json"); + output_.SendBody(writer.write(value)); } alreadySent_ = true; @@ -95,7 +104,8 @@ const std::string& contentType) { CheckStatus(); - output_.AnswerBufferWithContentType(buffer, contentType); + output_.SetContentType(contentType.c_str()); + output_.SendBody(buffer); alreadySent_ = true; } @@ -104,7 +114,8 @@ const std::string& contentType) { CheckStatus(); - output_.AnswerBufferWithContentType(buffer, length, contentType); + output_.SetContentType(contentType.c_str()); + output_.SendBody(buffer, length); alreadySent_ = true; } @@ -124,7 +135,7 @@ } CheckStatus(); - output_.SendHeader(status); + output_.SendStatus(status); alreadySent_ = true; }