Mercurial > hg > orthanc
comparison Core/RestApi/RestApiOutput.cpp @ 1511:7962563129c9
starting support of deflate/gzip content types
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Aug 2015 14:18:24 +0200 |
parents | f967bdf8534e |
children | d73a2178b319 |
comparison
equal
deleted
inserted
replaced
1510:ffc9f36103b9 | 1511:7962563129c9 |
---|---|
43 { | 43 { |
44 RestApiOutput::RestApiOutput(HttpOutput& output, | 44 RestApiOutput::RestApiOutput(HttpOutput& output, |
45 HttpMethod method) : | 45 HttpMethod method) : |
46 output_(output), | 46 output_(output), |
47 method_(method), | 47 method_(method), |
48 compression_(HttpCompression_None), | |
48 convertJsonToXml_(false) | 49 convertJsonToXml_(false) |
49 { | 50 { |
50 alreadySent_ = false; | 51 alreadySent_ = false; |
51 } | 52 } |
52 | 53 |
92 { | 93 { |
93 #if ORTHANC_PUGIXML_ENABLED == 1 | 94 #if ORTHANC_PUGIXML_ENABLED == 1 |
94 std::string s; | 95 std::string s; |
95 Toolbox::JsonToXml(s, value); | 96 Toolbox::JsonToXml(s, value); |
96 output_.SetContentType("application/xml"); | 97 output_.SetContentType("application/xml"); |
97 output_.SendBody(s); | 98 output_.SendBody(s, compression_); |
98 #else | 99 #else |
99 LOG(ERROR) << "Orthanc was compiled without XML support"; | 100 LOG(ERROR) << "Orthanc was compiled without XML support"; |
100 throw OrthancException(ErrorCode_InternalError); | 101 throw OrthancException(ErrorCode_InternalError); |
101 #endif | 102 #endif |
102 } | 103 } |
103 else | 104 else |
104 { | 105 { |
105 Json::StyledWriter writer; | 106 Json::StyledWriter writer; |
106 output_.SetContentType("application/json"); | 107 output_.SetContentType("application/json"); |
107 output_.SendBody(writer.write(value)); | 108 output_.SendBody(writer.write(value), compression_); |
108 } | 109 } |
109 | 110 |
110 alreadySent_ = true; | 111 alreadySent_ = true; |
111 } | 112 } |
112 | 113 |
113 void RestApiOutput::AnswerBuffer(const std::string& buffer, | 114 void RestApiOutput::AnswerBuffer(const std::string& buffer, |
114 const std::string& contentType) | 115 const std::string& contentType) |
115 { | 116 { |
116 CheckStatus(); | 117 CheckStatus(); |
117 output_.SetContentType(contentType.c_str()); | 118 output_.SetContentType(contentType.c_str()); |
118 output_.SendBody(buffer); | 119 output_.SendBody(buffer, compression_); |
119 alreadySent_ = true; | 120 alreadySent_ = true; |
120 } | 121 } |
121 | 122 |
122 void RestApiOutput::AnswerBuffer(const void* buffer, | 123 void RestApiOutput::AnswerBuffer(const void* buffer, |
123 size_t length, | 124 size_t length, |
124 const std::string& contentType) | 125 const std::string& contentType) |
125 { | 126 { |
126 CheckStatus(); | 127 CheckStatus(); |
127 output_.SetContentType(contentType.c_str()); | 128 output_.SetContentType(contentType.c_str()); |
128 output_.SendBody(buffer, length); | 129 output_.SendBody(buffer, length, compression_); |
129 alreadySent_ = true; | 130 alreadySent_ = true; |
130 } | 131 } |
131 | 132 |
132 void RestApiOutput::Redirect(const std::string& path) | 133 void RestApiOutput::Redirect(const std::string& path) |
133 { | 134 { |