Commit 0ec4c66f authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

fixed -F to support setting type= even on parts that aren't file-uploads

parent 1faa9d6f
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,10 @@
                                  Changelog

Daniel (10 September 2004)
- As found out by Jonas Forsman, curl didn't allow -F to set Content-Type on
  text-parts. Starting now, we can do -F "name=daniel;type=text/extra". Added
  test case 186 to verify.

- Bug report #1025986. When following a Location: with a custom Host: header
  replacement, curl only replaced the Host: header on the initial request
  and didn't replace it on the following ones. This resulted in requests with
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ This release includes the following changes:

This release includes the following bugfixes:

 o -F can now add Content-Type on non-file sections
 o double Host: header when following Location: with replaced Host: fixed
 o curl_multi_add_handle() return code fix
 o "Proxy-Connection: close" is now understood and properly dealt with
+7 −3
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ If this option is used twice, the second will again disable silent failure.
If this option is used twice, the second will again disable silent failure.
.IP "-F/--form <name=content>"
(HTTP) This lets curl emulate a filled in form in which a user has pressed the
submit button. This causes curl to POST data using the content-type
submit button. This causes curl to POST data using the Content-Type
multipart/form-data according to RFC1867. This enables uploading of binary
files etc. To force the 'content' part to be be a file, prefix the file name
with an @ sign. To just get the content part from a file, prefix the file name
@@ -355,11 +355,15 @@ input:
To read the file's content from stdin insted of a file, use - where the file
name should've been. This goes for both @ and < constructs.

You can also tell curl what Content-Type to use for the file upload part, by
using 'type=', in a manner similar to:
You can also tell curl what Content-Type to use by using 'type=', in a manner
similar to:

\fBcurl\fP -F "web=@index.html;type=text/html" url.com

or

\fBcurl\fP -F "name=daniel;type=text/foo" url.com

See further examples and details in the MANUAL.

This option can be used multiple times.
+28 −5
Original line number Diff line number Diff line
@@ -920,19 +920,42 @@ static int formparse(char *input,
      }
    }
    else {
      struct curl_forms info[4];
      int i = 0;
      char *ct = strstr(contp, ";type=");

      info[i].option = CURLFORM_COPYNAME;
      info[i].value = name;
      i++;

      if(ct) {
        info[i].option = CURLFORM_CONTENTTYPE;
        info[i].value = &ct[6];
        i++;
        ct[0]=0; /* zero terminate here */
      }

      if( contp[0]=='<' ) {
        info[i].option = CURLFORM_FILECONTENT;
        info[i].value = contp+1;
        i++;
        info[i].option = CURLFORM_END;

        if (curl_formadd(httppost, last_post,
                         CURLFORM_COPYNAME, name,
                         CURLFORM_FILECONTENT, contp+1, CURLFORM_END) != 0) {
          fprintf(stderr, "curl_formadd failed!\n");
                         CURLFORM_ARRAY, info, CURLFORM_END ) != 0) {
          fprintf(stderr, "curl_formadd failed, possibly the file %s is bad!\n",
                  contp+1);
          free(contents);
          return 6;
        }
      }
      else {
        info[i].option = CURLFORM_COPYCONTENTS;
        info[i].value = contp;
        i++;
        info[i].option = CURLFORM_END;
        if (curl_formadd(httppost, last_post,
                         CURLFORM_COPYNAME, name,
                         CURLFORM_COPYCONTENTS, contp, CURLFORM_END) != 0) {
                         CURLFORM_ARRAY, info, CURLFORM_END) != 0) {
          fprintf(stderr, "curl_formadd failed!\n");
          free(contents);
          return 7;
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ EXTRA_DIST = test1 test108 test117 test127 test20 test27 test34 test46 \
 test512 test165 test166 test167 test168 test169 test170 test171	\
 test172 test204 test205 test173 test174 test175 test176 test177	\
 test513 test514 test178 test179 test180 test181 test182 test183	\
 test184 test185
 test184 test185 test186

# The following tests have been removed from the dist since they no longer
# work. We need to fix the test suite's FTPS server first, then bring them
Loading