|
|
@ -507,6 +507,7 @@ namespace client |
|
|
|
<< "Host: " << u.host_ << "\r\n" |
|
|
|
<< "Host: " << u.host_ << "\r\n" |
|
|
|
<< "Accept: */*\r\n" |
|
|
|
<< "Accept: */*\r\n" |
|
|
|
<< "User-Agent: Wget/1.11.4\r\n" |
|
|
|
<< "User-Agent: Wget/1.11.4\r\n" |
|
|
|
|
|
|
|
//<< "Accept-Encoding: gzip\r\n"
|
|
|
|
<< "Connection: close\r\n"; |
|
|
|
<< "Connection: close\r\n"; |
|
|
|
if (m_Etag.length () > 0) // etag
|
|
|
|
if (m_Etag.length () > 0) // etag
|
|
|
|
request << i2p::util::http::IF_NONE_MATCH << ": \"" << m_Etag << "\"\r\n"; |
|
|
|
request << i2p::util::http::IF_NONE_MATCH << ": \"" << m_Etag << "\"\r\n"; |
|
|
@ -545,7 +546,7 @@ namespace client |
|
|
|
response >> status; // status
|
|
|
|
response >> status; // status
|
|
|
|
if (status == 200) // OK
|
|
|
|
if (status == 200) // OK
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bool isChunked = false; |
|
|
|
bool isChunked = false, isGzip = false; |
|
|
|
std::string header, statusMessage; |
|
|
|
std::string header, statusMessage; |
|
|
|
std::getline (response, statusMessage); |
|
|
|
std::getline (response, statusMessage); |
|
|
|
// read until new line meaning end of header
|
|
|
|
// read until new line meaning end of header
|
|
|
@ -563,6 +564,8 @@ namespace client |
|
|
|
m_LastModified = header.substr (colon + 1); |
|
|
|
m_LastModified = header.substr (colon + 1); |
|
|
|
else if (field == i2p::util::http::TRANSFER_ENCODING) |
|
|
|
else if (field == i2p::util::http::TRANSFER_ENCODING) |
|
|
|
isChunked = !header.compare (colon + 1, std::string::npos, "chunked"); |
|
|
|
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"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
LogPrint (eLogInfo, "Addressbook: ", m_Link, " ETag: ", m_Etag, " Last-Modified: ", m_LastModified); |
|
|
|
LogPrint (eLogInfo, "Addressbook: ", m_Link, " ETag: ", m_Etag, " Last-Modified: ", m_LastModified); |
|
|
@ -570,13 +573,13 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
success = true; |
|
|
|
success = true; |
|
|
|
if (!isChunked) |
|
|
|
if (!isChunked) |
|
|
|
m_Book.LoadHostsFromStream (response); |
|
|
|
success = ProcessResponse (response, isGzip); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// merge chunks
|
|
|
|
// merge chunks
|
|
|
|
std::stringstream merged; |
|
|
|
std::stringstream merged; |
|
|
|
i2p::util::http::MergeChunkedResponse (response, merged); |
|
|
|
i2p::util::http::MergeChunkedResponse (response, merged); |
|
|
|
m_Book.LoadHostsFromStream (merged); |
|
|
|
success = ProcessResponse (merged, isGzip); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -599,6 +602,23 @@ namespace client |
|
|
|
|
|
|
|
|
|
|
|
m_Book.DownloadComplete (success); |
|
|
|
m_Book.DownloadComplete (success); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool AddressBookSubscription::ProcessResponse (std::stringstream& s, bool isGzip) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (isGzip) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::stringstream uncompressed; |
|
|
|
|
|
|
|
i2p::data::GzipInflator inflator; |
|
|
|
|
|
|
|
inflator.Inflate (s, uncompressed); |
|
|
|
|
|
|
|
if (!uncompressed.fail ()) |
|
|
|
|
|
|
|
m_Book.LoadHostsFromStream (uncompressed); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
m_Book.LoadHostsFromStream (s); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|