Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

curl_formadd does not add content type header #1986

Closed
moteus opened this issue Oct 12, 2017 · 3 comments
Closed

curl_formadd does not add content type header #1986

moteus opened this issue Oct 12, 2017 · 3 comments
Assignees

Comments

@moteus
Copy link

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_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

@bagder bagder changed the title curl_form does not add text/plain content type header curl_formadd does not add content type header Oct 12, 2017
@monnerat monnerat self-assigned this Oct 12, 2017
@monnerat
Copy link
Contributor

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
Copy link
Member

bagder commented Oct 12, 2017

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

@monnerat
Copy link
Contributor

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

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants