Mercurial > hg > orthanc
comparison Core/HttpServer/HttpOutput.cpp @ 1514:d73a2178b319
support of deflate and gzip content-types
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Aug 2015 16:43:59 +0200 |
parents | 7962563129c9 |
children | 4f8c8ef114db |
comparison
equal
deleted
inserted
replaced
1513:fe07f82d83d3 | 1514:d73a2178b319 |
---|---|
34 #include "HttpOutput.h" | 34 #include "HttpOutput.h" |
35 | 35 |
36 #include "../Logging.h" | 36 #include "../Logging.h" |
37 #include "../OrthancException.h" | 37 #include "../OrthancException.h" |
38 #include "../Toolbox.h" | 38 #include "../Toolbox.h" |
39 #include "../Compression/GzipCompressor.h" | |
39 #include "../Compression/ZlibCompressor.h" | 40 #include "../Compression/ZlibCompressor.h" |
40 | 41 |
41 #include <iostream> | 42 #include <iostream> |
42 #include <vector> | 43 #include <vector> |
43 #include <stdio.h> | 44 #include <stdio.h> |
273 { | 274 { |
274 stateMachine_.SendBody(buffer, length); | 275 stateMachine_.SendBody(buffer, length); |
275 break; | 276 break; |
276 } | 277 } |
277 | 278 |
279 case HttpCompression_Gzip: | |
278 case HttpCompression_Deflate: | 280 case HttpCompression_Deflate: |
279 { | 281 { |
280 LOG(TRACE) << "Compressing a HTTP answer using Deflate"; | 282 std::string compressed, encoding; |
281 ZlibCompressor compressor; | 283 |
282 | 284 if (compression == HttpCompression_Deflate) |
283 // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate" | 285 { |
284 compressor.SetPrefixWithUncompressedSize(false); | 286 encoding = "deflate"; |
285 | 287 ZlibCompressor compressor; |
286 std::string compressed; | 288 // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate" |
287 compressor.Compress(compressed, buffer, length); | 289 compressor.SetPrefixWithUncompressedSize(false); |
290 compressor.Compress(compressed, buffer, length); | |
291 } | |
292 else | |
293 { | |
294 encoding = "gzip"; | |
295 GzipCompressor compressor; | |
296 compressor.Compress(compressed, buffer, length); | |
297 } | |
298 | |
299 LOG(TRACE) << "Compressing a HTTP answer using " << encoding; | |
288 | 300 |
289 // The body is empty, do not use Deflate compression | 301 // The body is empty, do not use Deflate compression |
290 if (compressed.size() == 0) | 302 if (compressed.size() == 0) |
291 { | 303 { |
292 stateMachine_.SendBody(NULL, 0); | 304 stateMachine_.SendBody(NULL, 0); |
293 } | 305 } |
294 else | 306 else |
295 { | 307 { |
296 stateMachine_.AddHeader("Content-Encoding", "deflate"); | 308 stateMachine_.AddHeader("Content-Encoding", encoding); |
297 stateMachine_.SendBody(compressed.c_str(), compressed.size()); | 309 stateMachine_.SendBody(compressed.c_str(), compressed.size()); |
298 } | 310 } |
299 | 311 |
300 break; | 312 break; |
301 } | 313 } |