forked from organicmaps/organicmaps
deflate encoding support for http client curl
This commit is contained in:
parent
789b8416f2
commit
da7a03b437
2 changed files with 24 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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 <unistd.h> // 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
|
||||
|
|
Loading…
Add table
Reference in a new issue