Include test cases in 554, 587, 650.
Fixes https://github.com/curl/curl/issues/1986
result = curl_mime_headers(part, file->contentheader, 0);
/* Set the content type. */
- if(!result &&file->contenttype)
+ if(!result && file->contenttype)
result = curl_mime_type(part, file->contenttype);
/* Set field name. */
{
curl_mime *mime = NULL;
const char *boundary = NULL;
- char *s;
+ char *customct;
const char *cte = NULL;
CURLcode ret = CURLE_OK;
if(part->state.state == MIMESTATE_CURLHEADERS)
mimesetstate(&part->state, MIMESTATE_CURLHEADERS, NULL);
- /* Build the content-type header. */
- s = search_header(part->userheaders, "Content-Type");
- if(s)
- contenttype = s;
- if(part->mimetype)
- contenttype = part->mimetype;
+ /* Check if content type is specified. */
+ customct = part->mimetype;
+ if(!customct)
+ customct = search_header(part->userheaders, "Content-Type");
+ if(customct)
+ contenttype = customct;
+
+ /* If content type is not specified, try to determine it. */
if(!contenttype) {
switch(part->kind) {
case MIMEKIND_MULTIPART:
if(mime)
boundary = mime->boundary;
}
- else if(contenttype && strcasecompare(contenttype, "text/plain"))
+ else if(contenttype && !customct &&
+ strcasecompare(contenttype, "text/plain"))
if(strategy == MIMESTRATEGY_MAIL || !part->filename)
contenttype = NULL;
POST /554 HTTP/1.1\r
Host: %HOSTIP:%HTTPPORT\r
Accept: */*\r
-Content-Length: 718\r
+Content-Length: 744\r
Content-Type: multipart/form-data; boundary=----------------------------\r
\r
------------------------------\r
postit2.c\r
------------------------------\r
Content-Disposition: form-data; name="submit"\r
+Content-Type: text/plain\r
\r
send\r
------------------------------\r
POST /554 HTTP/1.1\r
Host: %HOSTIP:%HTTPPORT\r
Accept: */*\r
-Content-Length: 732\r
+Content-Length: 758\r
Content-Type: multipart/form-data; boundary=----------------------------\r
\r
------------------------------\r
postit2.c\r
------------------------------\r
Content-Disposition: form-data; name="submit"\r
+Content-Type: text/plain\r
\r
send\r
------------------------------\r
POST /587 HTTP/1.1\r
Host: %HOSTIP:%HTTPPORT\r
Accept: */*\r
-Content-Length: 718\r
+Content-Length: 744\r
Content-Type: multipart/form-data; boundary=----------------------------\r
\r
------------------------------\r
Content-Type: multipart/form-data; boundary=----------------------------\r
Expect: 100-continue\r
\r
-5f0\r
+60a\r
------------------------------\r
Content-Disposition: form-data; name="fieldname"\r
+Content-Type: text/plain\r
+X-customheader-1: Header 1 data\r
+X-customheader-2: Header 2 data\r
\r
this is what we post to the silly web server\r
------------------------------\r
\r
------------------------------\r
Content-Disposition: form-data; name="filecontents"\r
-X-customheader-1: Header 1 data\r
-X-customheader-2: Header 2 data\r
\r
This is data from a file.
\r
------------------------------\r
Content-Disposition: form-data; name="formlength"\r
\r
-1341\r
+1367\r
------------------------------\r
Content-Disposition: form-data; name="standardinput"\r
Content-Type: application/octet-stream\r
CURLFORM_END);
if(formrc)
- printf("curl_formadd(1) = %d\n", (int)formrc);
+ printf("curl_formadd(2) = %d\n", (int)formrc);
/* Fill in the filename field */
formrc = curl_formadd(&formpost,
CURLFORM_END);
if(formrc)
- printf("curl_formadd(2) = %d\n", (int)formrc);
+ printf("curl_formadd(3) = %d\n", (int)formrc);
/* Fill in a submit field too */
formrc = curl_formadd(&formpost,
#else
CURLFORM_COPYCONTENTS, "send",
#endif
+ CURLFORM_CONTENTTYPE, "text/plain",
CURLFORM_END);
if(formrc)
- printf("curl_formadd(3) = %d\n", (int)formrc);
+ printf("curl_formadd(4) = %d\n", (int)formrc);
formrc = curl_formadd(&formpost, &lastptr,
CURLFORM_COPYNAME, "somename",
CURLFORM_END);
if(formrc)
- printf("curl_formadd(4) = %d\n", (int)formrc);
+ printf("curl_formadd(5) = %d\n", (int)formrc);
curl = curl_easy_init();
if(!curl) {
return TEST_ERR_MAJOR_BAD;
}
- /* Check proper name and data copying. */
+ /* Check proper name and data copying, as well as headers. */
+ headers = curl_slist_append(headers, "X-customheader-1: Header 1 data");
+ headers = curl_slist_append(headers, "X-customheader-2: Header 2 data");
+ headers = curl_slist_append(headers, "Content-Type: text/plain");
formrc = curl_formadd(&formpost, &lastptr,
CURLFORM_COPYNAME, &name,
CURLFORM_COPYCONTENTS, &data,
+ CURLFORM_CONTENTHEADER, headers,
CURLFORM_END);
if(formrc)
if(formrc)
printf("curl_formadd(3) = %d\n", (int) formrc);
- /* Check data from file content and headers. */
- headers = curl_slist_append(headers, "X-customheader-1: Header 1 data");
- headers = curl_slist_append(headers, "X-customheader-2: Header 2 data");
+ /* Check data from file content. */
formrc = curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "filecontents",
CURLFORM_FILECONTENT, libtest_arg2,
- CURLFORM_CONTENTHEADER, headers,
CURLFORM_END);
if(formrc)
- printf("curl_formadd(3) = %d\n", (int) formrc);
+ printf("curl_formadd(4) = %d\n", (int) formrc);
/* Measure the current form length.
* This is done before including stdin data because we want to reuse it
CURLFORM_END);
if(formrc)
- printf("curl_formadd(4) = %d\n", (int) formrc);
+ printf("curl_formadd(5) = %d\n", (int) formrc);
curl = curl_easy_init();
if(!curl) {