1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

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

This commit is contained in:
Daniel Stenberg 2004-09-10 21:47:52 +00:00
parent 1faa9d6fd5
commit 0ec4c66fba
6 changed files with 95 additions and 9 deletions

View File

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

View File

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

View File

@ -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.

View File

@ -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;

View File

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

54
tests/data/test186 Normal file
View File

@ -0,0 +1,54 @@
# Server-side
<reply>
<data>
HTTP/1.1 200 OK swsclose
Date: Thu, 09 Nov 2010 14:49:00 GMT
Server: test-server/fake
blablabla
</data>
</reply>
# Client-side
<client>
<server>
http
</server>
<name>
HTTP RFC1867-type formposting with types on text fields
</name>
<command>
http://%HOSTIP:%HTTPPORT/we/want/186 -F "name=daniel;type=moo/foo" -F "html= <body>hello</body>;type=text/html"
</command>
# We create this file before the command is invoked!
</client>
# Verify data after the test has been "shot"
<verify>
<strip>
^(User-Agent:|Content-Type: multipart/form-data;|------------).*
</strip>
<protocol>
POST /we/want/186 HTTP/1.1
User-Agent: curl/7.12.2-CVS (i686-pc-linux-gnu) libcurl/7.12.2-CVS OpenSSL/0.9.7d zlib/1.2.1.1 c-ares/1.2.0 libidn/0.5.2
Host: 127.0.0.1:%HTTPPORT
Pragma: no-cache
Accept: */*
Content-Length: 305
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------212d9006ceb5
------------------------------212d9006ceb5
Content-Disposition: form-data; name="name"
Content-Type: moo/foo
daniel
------------------------------212d9006ceb5
Content-Disposition: form-data; name="html"
Content-Type: text/html
<body>hello</body>
------------------------------212d9006ceb5--
</protocol>
</verify>