Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/Core/HttpServer/HttpOutput.cpp Mon Aug 10 16:01:37 2015 +0200 +++ b/Core/HttpServer/HttpOutput.cpp Mon Aug 10 16:43:59 2015 +0200 @@ -36,6 +36,7 @@ #include "../Logging.h" #include "../OrthancException.h" #include "../Toolbox.h" +#include "../Compression/GzipCompressor.h" #include "../Compression/ZlibCompressor.h" #include <iostream> @@ -275,16 +276,27 @@ break; } + case HttpCompression_Gzip: case HttpCompression_Deflate: { - LOG(TRACE) << "Compressing a HTTP answer using Deflate"; - ZlibCompressor compressor; + std::string compressed, encoding; - // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate" - compressor.SetPrefixWithUncompressedSize(false); + if (compression == HttpCompression_Deflate) + { + encoding = "deflate"; + ZlibCompressor compressor; + // Do not prefix the buffer with its uncompressed size, to be compatible with "deflate" + compressor.SetPrefixWithUncompressedSize(false); + compressor.Compress(compressed, buffer, length); + } + else + { + encoding = "gzip"; + GzipCompressor compressor; + compressor.Compress(compressed, buffer, length); + } - std::string compressed; - compressor.Compress(compressed, buffer, length); + LOG(TRACE) << "Compressing a HTTP answer using " << encoding; // The body is empty, do not use Deflate compression if (compressed.size() == 0) @@ -293,7 +305,7 @@ } else { - stateMachine_.AddHeader("Content-Encoding", "deflate"); + stateMachine_.AddHeader("Content-Encoding", encoding); stateMachine_.SendBody(compressed.c_str(), compressed.size()); }