Skip to content

Empty Accept-Encoding: Header doesn't override CURLOPT_ACCEPT_ENCODING on 2nd request with reused handle #785

@rcanavan

Description

@rcanavan

The test program below (modified from examples/httpcustomheader.c) attempts to send 2 requests to a host, and reuse the curl handle. On the second request, it attempts to disable CURLOPT_ACCEPT_ENCODING by explicitly setting the Accept-Encoding:-header without a value.

This works as expected (i.e. no Accept-Encoding header is sent in the request) only if a "fresh" handle is used or no previous request with that handle has ever actually sent a request with the Accept-Encoding header set via CURLOPT_ACCEPT_ENCODING.

#include <stdio.h>
#include <curl/curl.h>
CURL *curl;

void request(char * url, int compress)
{
  CURLcode res;

  if(curl) {
    struct curl_slist *chunk = NULL;
    curl_easy_setopt(curl, CURLOPT_URL, url);
    res = curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "");
    if (compress == 0) {
        chunk = curl_slist_append(chunk, "Accept-Encoding: ");
    }
    res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
    //curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    res = curl_easy_perform(curl);
    if(res != CURLE_OK) fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));

    curl_easy_reset(curl);
    curl_slist_free_all(chunk);
  }
}

int main(void)
{
  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  request("http://localhost:14080/headers.php", 1);
  request("http://localhost:14080/headers.php", 0);
  curl_easy_cleanup(curl);
  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions