diff --git a/platform/http_client.cpp b/platform/http_client.cpp index 3ed40624f8..99fd9b34be 100644 --- a/platform/http_client.cpp +++ b/platform/http_client.cpp @@ -10,7 +10,7 @@ namespace platform { HttpClient::HttpClient(string const & url) : m_urlRequested(url) { - m_headers.emplace("Accept-Encoding", "gzip, deflate"); + m_headers.emplace("Accept-Encoding", "deflate"); } HttpClient & HttpClient::SetUrlRequested(string const & url) diff --git a/platform/http_client_curl.cpp b/platform/http_client_curl.cpp index e7ba50beba..c411260a34 100644 --- a/platform/http_client_curl.cpp +++ b/platform/http_client_curl.cpp @@ -24,6 +24,8 @@ #include "platform/http_client.hpp" #include "platform/platform.hpp" +#include "coding/zlib.hpp" + #include "base/assert.hpp" #include "base/exception.hpp" #include "base/logging.hpp" @@ -47,6 +49,8 @@ #include // close #endif +using namespace coding; + namespace { DECLARE_EXCEPTION(PipeCallError, RootException); @@ -144,6 +148,18 @@ bool WriteToFile(string const & fileName, string const & data) ofs << data; return true; } + +std::string Decompress(std::string const & compressed, std::string const & encoding) +{ + std::string decompressed; + + if (encoding == "deflate") + ZLib::Inflate(compressed, back_inserter(decompressed)); + else + ASSERT(false, ("Unsupported Content-Encoding:", encoding)); + + return decompressed; +} } // namespace // Used as a test stub for basic HTTP client implementation. // Make sure that you have curl installed in the PATH. @@ -260,6 +276,13 @@ bool HttpClient::RunHttpRequest() m_serverResponse = move(redirect.m_serverResponse); } + auto const it = m_headers.find("content-encoding"); + if (it != m_headers.end()) + { + m_serverResponse = Decompress(m_serverResponse, it->second); + LOG(LDEBUG, ("Response with", it->second, "is decompressed.")); + } + return true; } } // namespace platform