Mercurial > hg > orthanc
comparison Core/RestApi/RestApiOutput.cpp @ 1517:4f8c8ef114db
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Aug 2015 10:32:34 +0200 |
parents | c94353fbd4e9 |
children | eb46cc06389a |
comparison
equal
deleted
inserted
replaced
1516:f09f5d3225a7 | 1517:4f8c8ef114db |
---|---|
115 | 115 |
116 void RestApiOutput::AnswerJson(const Json::Value& value) | 116 void RestApiOutput::AnswerJson(const Json::Value& value) |
117 { | 117 { |
118 CheckStatus(); | 118 CheckStatus(); |
119 | 119 |
120 std::string s; | |
121 | |
122 if (convertJsonToXml_) | 120 if (convertJsonToXml_) |
123 { | 121 { |
124 #if ORTHANC_PUGIXML_ENABLED == 1 | 122 #if ORTHANC_PUGIXML_ENABLED == 1 |
123 std::string s; | |
125 Toolbox::JsonToXml(s, value); | 124 Toolbox::JsonToXml(s, value); |
126 output_.SetContentType("application/xml"); | 125 output_.SetContentType("application/xml"); |
126 output_.SendBody(s); | |
127 #else | 127 #else |
128 LOG(ERROR) << "Orthanc was compiled without XML support"; | 128 LOG(ERROR) << "Orthanc was compiled without XML support"; |
129 throw OrthancException(ErrorCode_InternalError); | 129 throw OrthancException(ErrorCode_InternalError); |
130 #endif | 130 #endif |
131 } | 131 } |
132 else | 132 else |
133 { | 133 { |
134 Json::StyledWriter writer; | 134 Json::StyledWriter writer; |
135 output_.SetContentType("application/json"); | 135 output_.SetContentType("application/json"); |
136 s = writer.write(value); | 136 output_.SendBody(writer.write(value)); |
137 } | 137 } |
138 | |
139 output_.SendBody(s, GetPreferredCompression(s.size())); | |
140 | 138 |
141 alreadySent_ = true; | 139 alreadySent_ = true; |
142 } | 140 } |
143 | 141 |
144 void RestApiOutput::AnswerBuffer(const std::string& buffer, | 142 void RestApiOutput::AnswerBuffer(const std::string& buffer, |
152 size_t length, | 150 size_t length, |
153 const std::string& contentType) | 151 const std::string& contentType) |
154 { | 152 { |
155 CheckStatus(); | 153 CheckStatus(); |
156 output_.SetContentType(contentType.c_str()); | 154 output_.SetContentType(contentType.c_str()); |
157 output_.SendBody(buffer, length, GetPreferredCompression(length)); | 155 output_.SendBody(buffer, length); |
158 alreadySent_ = true; | 156 alreadySent_ = true; |
159 } | 157 } |
160 | 158 |
161 void RestApiOutput::Redirect(const std::string& path) | 159 void RestApiOutput::Redirect(const std::string& path) |
162 { | 160 { |