Skip to content

Commit 0afcbb6

Browse files
authored
Enable all supported encoding compressions in curl. (#8437)
1 parent 32971e8 commit 0afcbb6

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

libs/openFrameworks/utils/ofURLFileLoader.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,34 @@ ofHttpResponse ofURLFileLoaderImpl::handleRequest(const ofHttpRequest & request)
339339
if (request.contentType != "") {
340340
headers = curl_slist_append(headers, ("Content-Type: " + request.contentType).c_str());
341341
}
342-
if(request.close)
342+
if(request.close) {
343343
headers = curl_slist_append(headers, "Connection: close");
344-
if(version->features & CURL_VERSION_BROTLI) {
345-
headers = curl_slist_append(headers, "Accept-Encoding: br");
346-
}
347-
if(version->features & CURL_VERSION_LIBZ) {
348-
headers = curl_slist_append(headers, "Accept-Encoding: gzip");
349344
}
345+
// https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html
346+
// the following is used for requesting specific compression encodings
347+
// if the headers are set with the encodings, then curl will not decompress the received data
348+
// leaving this here for future reference
349+
// std::string encodings = "Accept-Encoding: ";
350+
// bool first = true;
351+
//
352+
// if (version->features & CURL_VERSION_BROTLI) {
353+
// encodings += "br";
354+
// first = false;
355+
// }
356+
// if (version->features & CURL_VERSION_LIBZ) {
357+
// if (!first) {encodings += ", ";}
358+
// encodings += "gzip";
359+
// first = false;
360+
// }
361+
// if( !first) {
362+
// ofLogVerbose("ofURLFileLoader :: encodings") << encodings;
363+
// headers = curl_slist_append(headers, encodings.c_str());
364+
// } else {
365+
// curl_easy_setopt(curl.get(), CURLOPT_ACCEPT_ENCODING, "");
366+
// }
367+
/* enable all supported built-in compressions */
368+
curl_easy_setopt(curl.get(), CURLOPT_ACCEPT_ENCODING, "");
369+
350370
for (map<string, string>::const_iterator it = request.headers.cbegin(); it != request.headers.cend(); it++) {
351371
headers = curl_slist_append(headers, (it->first + ": " + it->second).c_str());
352372
}

0 commit comments

Comments
 (0)