]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
c-hyper: support automatic content-encoding
authorDaniel Stenberg <daniel@haxx.se>
Thu, 11 Mar 2021 15:05:15 +0000 (16:05 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 11 Mar 2021 21:45:26 +0000 (22:45 +0100)
Closes #6727

lib/c-hyper.c

index c3a16cf82f7e63d56f311fef426ad40ef701e2c5..3238ceed1dfd0f07b82f5becfa71f8dd1d9ddc6e 100644 (file)
@@ -51,6 +51,7 @@
 #include "transfer.h"
 #include "multiif.h"
 #include "progress.h"
+#include "content_encoding.h"
 
 /* The last 3 #include files should be in this order */
 #include "curl_printf.h"
@@ -175,7 +176,11 @@ static int hyper_body_chunk(void *userdata, const hyper_buf *chunk)
   if(k->ignorebody)
     return HYPER_ITER_CONTINUE;
   Curl_debug(data, CURLINFO_DATA_IN, buf, len);
-  result = Curl_client_write(data, CLIENTWRITE_BODY, buf, len);
+  if(!data->set.http_ce_skip && k->writer_stack)
+    /* content-encoded data */
+    result = Curl_unencode_write(data, k->writer_stack, buf, len);
+  else
+    result = Curl_client_write(data, CLIENTWRITE_BODY, buf, len);
 
   if(result) {
     data->state.hresult = result;
@@ -813,6 +818,19 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
       goto error;
   }
 
+  if(!Curl_checkheaders(data, "Accept-Encoding") &&
+     data->set.str[STRING_ENCODING]) {
+    Curl_safefree(data->state.aptr.accept_encoding);
+    data->state.aptr.accept_encoding =
+      aprintf("Accept-Encoding: %s\r\n", data->set.str[STRING_ENCODING]);
+    if(!data->state.aptr.accept_encoding)
+      return CURLE_OUT_OF_MEMORY;
+    if(Curl_hyper_header(data, headers, data->state.aptr.accept_encoding))
+      goto error;
+  }
+  else
+    Curl_safefree(data->state.aptr.accept_encoding);
+
   result = cookies(data, conn, headers);
   if(result)
     return result;