From 3053a9b6a0bc417202b1720d4e73b6ef22d7f969 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 18 Feb 2016 20:35:14 -0500 Subject: [PATCH] enable i2p gzip compression --- AddressBook.cpp | 4 ++++ Base.cpp | 5 +++-- Base.h | 2 +- util.h | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index ca96882e..006d503c 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -508,6 +508,7 @@ namespace client << "Accept: */*\r\n" << "User-Agent: Wget/1.11.4\r\n" //<< "Accept-Encoding: gzip\r\n" + << "X-Accept-Encoding: x-i2p-gzip;q=1.0, identity;q=0.5, deflate;q=0, gzip;q=0, *;q=0\r\n" << "Connection: close\r\n"; if (m_Etag.length () > 0) // etag request << i2p::util::http::IF_NONE_MATCH << ": \"" << m_Etag << "\"\r\n"; @@ -557,6 +558,7 @@ namespace client if (colon != std::string::npos) { std::string field = header.substr (0, colon); + colon++; header.resize (header.length () - 1); // delete \r if (field == i2p::util::http::ETAG) m_Etag = header.substr (colon + 1); @@ -566,6 +568,8 @@ namespace client isChunked = !header.compare (colon + 1, std::string::npos, "chunked"); else if (field == i2p::util::http::CONTENT_ENCODING) isGzip = !header.compare (colon + 1, std::string::npos, "gzip"); + else if (field == i2p::util::http::CONTENT_ENCODING1) // Content-encoding + isGzip = !header.compare (colon + 1, std::string::npos, "x-i2p-gzip"); } } LogPrint (eLogInfo, "Addressbook: ", m_Link, " ETag: ", m_Etag, " Last-Modified: ", m_LastModified); diff --git a/Base.cpp b/Base.cpp index 813b8dfa..cb6faf2d 100644 --- a/Base.cpp +++ b/Base.cpp @@ -329,9 +329,10 @@ namespace data return ret == Z_STREAM_END || ret < 0; } - void GzipInflator::Inflate (const std::stringstream& in, std::ostream& out) + void GzipInflator::Inflate (std::stringstream& in, std::ostream& out) { - Inflate ((const uint8_t *)in.str ().c_str (), in.str ().length (), out); + auto str = in.str ().substr (in.tellg ()); + Inflate ((const uint8_t *)str.c_str (), str.length (), out); } GzipDeflator::GzipDeflator (): m_IsDirty (false) diff --git a/Base.h b/Base.h index b5ac04c3..19dc31da 100644 --- a/Base.h +++ b/Base.h @@ -105,7 +105,7 @@ namespace data size_t Inflate (const uint8_t * in, size_t inLen, uint8_t * out, size_t outLen); bool Inflate (const uint8_t * in, size_t inLen, std::ostream& s); // return true when finshed or error, s failbit will be set in case of error - void Inflate (const std::stringstream& in, std::ostream& out); + void Inflate (std::stringstream& in, std::ostream& out); private: diff --git a/util.h b/util.h index 15765f37..3b05c170 100644 --- a/util.h +++ b/util.h @@ -35,7 +35,8 @@ namespace util const char LAST_MODIFIED[] = "Last-Modified"; const char TRANSFER_ENCODING[] = "Transfer-Encoding"; const char CONTENT_ENCODING[] = "Content-Encoding"; - + const char CONTENT_ENCODING1[] = "Content-encoding"; + std::string GetHttpContent (std::istream& response); void MergeChunkedResponse (std::istream& response, std::ostream& merged); std::string urlDecode(const std::string& data);