curl_formadd does not add content type header #1986

moteus opened this Issue Oct 12, 2017 · 3 comments


None yet
3 participants

moteus commented Oct 12, 2017

I did this

static size_t append_writer(void *arg, const char *buf, size_t len){
  char *buffer = arg;
  char *ptr = buffer + strlen(buffer);
  strcpy(ptr, buf);
  return len;

static void test_form_write_content_type(){
  char data[1024] = {0};
  const char *content_text = NULL;

  struct curl_httppost *post=NULL, *last=NULL;
  char name[] = "name"; size_t name_len = sizeof(name) - 1;
  char cont[] = "data"; size_t cont_len = sizeof(cont) - 1;

  CURLcode code = curl_formadd(&post, &last,
    CURLFORM_PTRNAME,     name, CURLFORM_NAMELENGTH,   (long)name_len,
    CURLFORM_CONTENTTYPE, "text/plain",

  code = curl_formget(post, data, append_writer);

  content_text = strstr(data, "text/plain");
  // libcurl < 7.56.0 Has Content-Type: text/plain
  // libcurl 7.56.0 does not have Content-Type: text/plain


I expected the following

I think curl should add content type if user ask to add it.
Also I got same result if using slist with like

headers = curl_slist_append(headers, "Content-Type: text/plain");
curl_formadd(&post, &last,

curl/libcurl version

libcurl 7.56.0

operating system

@bagder bagder changed the title from curl_form does not add `text/plain` content type header to curl_formadd does not add content type header Oct 12, 2017

@monnerat monnerat self-assigned this Oct 12, 2017


monnerat commented Oct 12, 2017

Found the problem: text/plain is the default and mime removes it as not needed.
However it should be kept if explicitly set by the caller.
I've assigned myself.


bagder commented Oct 12, 2017

Maybe convert the recipe to a test case too while you're working on a fix!

@monnerat monnerat closed this in 0401734 Oct 12, 2017


monnerat commented Oct 12, 2017

Fixed by 0401734
@moteus: does it satisfy your needs ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment