]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
content_encoding: avoid getting all encodings unless necessary
authorDaniel Stenberg <daniel@haxx.se>
Mon, 9 Sep 2024 07:15:56 +0000 (09:15 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 9 Sep 2024 14:50:22 +0000 (16:50 +0200)
The error_do_write() function may very well return witout needing the
listing of all encoding types so postpone that call until it is needed.

Closes #14831

lib/content_encoding.c

index 734547d0066ea213f82133cc9710546657fd103b..c0b97f1f7dc12f38814c177c369dc1c9e8f2227a 100644 (file)
@@ -909,18 +909,18 @@ static CURLcode error_do_write(struct Curl_easy *data,
                                      struct Curl_cwriter *writer, int type,
                                      const char *buf, size_t nbytes)
 {
-  char all[256];
-  (void)Curl_all_content_encodings(all, sizeof(all));
-
   (void) writer;
   (void) buf;
   (void) nbytes;
 
   if(!(type & CLIENTWRITE_BODY) || !nbytes)
     return Curl_cwriter_write(data, writer->next, type, buf, nbytes);
-
-  failf(data, "Unrecognized content encoding type. "
-        "libcurl understands %s content encodings.", all);
+  else {
+    char all[256];
+    (void)Curl_all_content_encodings(all, sizeof(all));
+    failf(data, "Unrecognized content encoding type. "
+          "libcurl understands %s content encodings.", all);
+  }
   return CURLE_BAD_CONTENT_ENCODING;
 }