curl / Mailing Lists / curl-library / Single Mail

curl-library

Range + gzip Encoding = 0 byte body

From: Rainer Canavan <rainer+curlusers_at_7val.com>
Date: Wed, 26 Apr 2017 15:24:43 +0200

Hi,

we're trying to pass (some) incoming requests to another server using
libcurl and the corresponding response back to the client, i.e.
basically like a proxy.

For Requests with non-trivial Range:-Headers, and Accept-Encoding, if
the server does indeed uses gzip or compressed encoding, curl fails to
decompress the body because it is incomplete, and returns no content.
As far as I can see, no error is raised, and the request appears to be
successful. This can easily be reproduced with the trivial change to
examples/getinmemory.c shown below. I'm not sure what a correct
behavior for curl would be, i.e. flag this as an error, pass the "raw"
response body, or something completely different. I believe using
CURLOPT_DEBUGFUNCTION to extract the body would be an appropriate
workaround.

Other people have stumbled across this in the past, e.g.
https://forum.nginx.org/read.php?2,209738,209850

Rainer

diff --git a/docs/examples/getinmemory.c b/docs/examples/getinmemory.c
index fb79478..cb158f9 100644
--- a/docs/examples/getinmemory.c
+++ b/docs/examples/getinmemory.c
@@ -72,7 +72,9 @@ int main(void)
  curl_handle = curl_easy_init();

  /* specify URL to get */
- curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.example.com/");
+ curl_easy_setopt(curl_handle, CURLOPT_URL, "https://httpd.apache.org/");
+ curl_easy_setopt(curl_handle, CURLOPT_ACCEPT_ENCODING, "");
+ curl_easy_setopt(curl_handle, CURLOPT_RANGE, "0-10");

  /* send all data to this function */
  curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-04-26