Skip to content

curl_formadd does not add content type header #1986

@moteus

Description

@moteus

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_PTRCONTENTS, cont, LCURL_FORM_CONTENTLEN, (LCURL_LEN_TYPE)cont_len,
    CURLFORM_CONTENTTYPE, "text/plain",
    CURLFORM_END);

  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,
    CURLFORM_CONTENTHEADER, headers,
   ...

curl/libcurl version

libcurl 7.56.0

operating system

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions