simgear/io/HTTP*: added support for enabling compression when downloading.
Uses underlying curl library's CURLOPT_ACCEPT_ENCODING.
This commit is contained in:
@@ -304,6 +304,12 @@ void Client::makeRequest(const Request_ptr& r)
|
||||
curl_easy_setopt(curlRequest, CURLOPT_RANGE, range.c_str());
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "Have added CURLOPT_RANGE: '" << range << "'");
|
||||
}
|
||||
|
||||
const char* enc = r->getAcceptEncoding();
|
||||
if (enc) {
|
||||
curl_easy_setopt(curlRequest, CURLOPT_ACCEPT_ENCODING, const_cast<char*>(enc));
|
||||
SG_LOG(SG_GENERAL, SG_ALERT, "Have added CURLOPT_ACCEPT_ENCODING: '" << enc << "'");
|
||||
}
|
||||
|
||||
const std::string method = strutils::lowercase (r->method());
|
||||
if (method == "get") {
|
||||
|
||||
@@ -133,6 +133,24 @@ void Request::setRange(const std::string& range)
|
||||
_range = range;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Request::setAcceptEncoding(const char* enc)
|
||||
{
|
||||
if (enc) {
|
||||
_enc_set = true;
|
||||
_enc = enc;
|
||||
}
|
||||
else {
|
||||
_enc_set = false;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
const char* Request::getAcceptEncoding()
|
||||
{
|
||||
return (_enc_set) ? _enc.c_str() : nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void Request::requestStart()
|
||||
{
|
||||
|
||||
@@ -138,6 +138,17 @@ public:
|
||||
* if we are updating a file that was fully downloaded previously.
|
||||
*/
|
||||
virtual void setRange(const std::string& range);
|
||||
|
||||
/*
|
||||
* Control underlying curl library's automatic decompression support. <enc>
|
||||
* is passed directly to curl_easy_setopt(CURLOPT_ACCEPT_ENCODING); see
|
||||
* CURLOPT_ACCEPT_ENCODING(3) for details.
|
||||
*
|
||||
* E.g. pass env="" to allow any available compression algorithm.
|
||||
*/
|
||||
virtual void setAcceptEncoding(const char* enc);
|
||||
|
||||
const char* getAcceptEncoding();
|
||||
|
||||
virtual std::string method() const
|
||||
{ return _method; }
|
||||
@@ -269,6 +280,8 @@ public:
|
||||
std::string _method;
|
||||
std::string _url;
|
||||
std::string _range;
|
||||
bool _enc_set = false;
|
||||
std::string _enc;
|
||||
StringMap _request_headers;
|
||||
std::string _request_data;
|
||||
std::string _request_media_type;
|
||||
|
||||
Reference in New Issue
Block a user