Mercurial > hg > orthanc
comparison Core/RestApi/RestApi.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 |
---|---|
168 size_t bodySize) | 168 size_t bodySize) |
169 { | 169 { |
170 RestApiOutput wrappedOutput(output, method); | 170 RestApiOutput wrappedOutput(output, method); |
171 | 171 |
172 #if ORTHANC_PUGIXML_ENABLED == 1 | 172 #if ORTHANC_PUGIXML_ENABLED == 1 |
173 // Look if the user wishes XML answers instead of JSON | 173 { |
174 // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3 | 174 // Look if the client wishes XML answers instead of JSON |
175 Arguments::const_iterator it = headers.find("accept"); | 175 // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3 |
176 if (it != headers.end()) | 176 Arguments::const_iterator it = headers.find("accept"); |
177 { | 177 if (it != headers.end()) |
178 std::vector<std::string> accepted; | 178 { |
179 Toolbox::TokenizeString(accepted, it->second, ';'); | 179 std::vector<std::string> accepted; |
180 for (size_t i = 0; i < accepted.size(); i++) | 180 Toolbox::TokenizeString(accepted, it->second, ';'); |
181 { | 181 for (size_t i = 0; i < accepted.size(); i++) |
182 if (accepted[i] == "application/xml") | |
183 { | 182 { |
184 wrappedOutput.SetConvertJsonToXml(true); | 183 if (accepted[i] == "application/xml") |
184 { | |
185 wrappedOutput.SetConvertJsonToXml(true); | |
186 } | |
187 | |
188 if (accepted[i] == "application/json") | |
189 { | |
190 wrappedOutput.SetConvertJsonToXml(false); | |
191 } | |
185 } | 192 } |
186 | 193 } |
187 if (accepted[i] == "application/json") | 194 } |
195 #endif | |
196 | |
197 { | |
198 // Look if the client wishes HTTP compression | |
199 // https://en.wikipedia.org/wiki/HTTP_compression | |
200 Arguments::const_iterator it = headers.find("accept-encoding"); | |
201 if (it != headers.end()) | |
202 { | |
203 std::vector<std::string> encodings; | |
204 Toolbox::TokenizeString(encodings, it->second, ','); | |
205 for (size_t i = 0; i < encodings.size(); i++) | |
188 { | 206 { |
189 wrappedOutput.SetConvertJsonToXml(false); | 207 std::string s = Toolbox::StripSpaces(encodings[i]); |
208 if (s == "deflate") | |
209 { | |
210 wrappedOutput.SetHttpCompression(HttpCompression_Deflate); | |
211 } | |
212 | |
213 // TODO HttpCompression_Gzip ? | |
190 } | 214 } |
191 } | 215 } |
192 } | 216 } |
193 #endif | |
194 | 217 |
195 Arguments compiled; | 218 Arguments compiled; |
196 HttpToolbox::CompileGetArguments(compiled, getArguments); | 219 HttpToolbox::CompileGetArguments(compiled, getArguments); |
197 | 220 |
198 HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, bodyData, bodySize); | 221 HttpHandlerVisitor visitor(*this, wrappedOutput, method, headers, compiled, bodyData, bodySize); |