xref: /curl/tests/data/test1404 (revision 3fd80c7b)
1<testcase>
2# Based on test 1315
3<info>
4<keywords>
5HTTP
6HTTP FORMPOST
7HTTP file upload
8--libcurl
9</keywords>
10</info>
11
12# Server-side
13<reply>
14<data>
15HTTP/1.1 200 OK
16Date: Thu, 29 Jul 2008 14:49:00 GMT
17Server: test-server/fake
18Content-Length: 0
19Connection: close
20
21</data>
22</reply>
23
24# Client-side
25<client>
26<features>
27Mime
28</features>
29<server>
30http
31</server>
32<name>
33--libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder
34</name>
35<setenv>
36SSL_CERT_FILE=
37</setenv>
38<command>
39http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F name=value -F 'file=@%LOGDIR/test%TESTNUMBER.txt,%LOGDIR/test%TESTNUMBER.txt;type=magic/content;encoder=8bit,%LOGDIR/test%TESTNUMBER.txt;headers=X-testheader-1: header 1;headers=X-testheader-2: header 2' --libcurl %LOGDIR/test%TESTNUMBER.c
40</command>
41# We create this file before the command is invoked!
42<file name="%LOGDIR/test%TESTNUMBER.txt">
43dummy data
44</file>
45</client>
46
47# Verify data after the test has been "shot"
48<verify>
49<strip>
50-----+\w+
51</strip>
52<protocol>
53POST /we/want/%TESTNUMBER HTTP/1.1
54Host: %HOSTIP:%HTTPPORT
55User-Agent: curl/%VERSION
56Accept: */*
57Content-Length: 930
58Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
59
60------------------------------9ef8d6205763
61Content-Disposition: form-data; name="name"
62
63value
64------------------------------9ef8d6205763
65Content-Disposition: form-data; name="file"
66Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
67
68Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
69Content-Type: text/plain
70
71dummy data
72
73------------------------------9ef8d6205763
74Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
75Content-Type: magic/content
76Content-Transfer-Encoding: 8bit
77
78dummy data
79
80------------------------------9ef8d6205763
81Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
82Content-Type: text/plain
83X-testheader-1: header 1
84X-testheader-2: header 2
85
86dummy data
87
88------------------------------aaaaaaaaaaaa--
89
90------------------------------9ef8d6205763--
91</protocol>
92<stripfile>
93# curl's default user-agent varies with version, libraries etc.
94s/(USERAGENT, \")[^\"]+/${1}stripped/
95# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
96# configurations - just ignore them
97$_ = '' if /CURLOPT_SSL_VERIFYPEER/
98$_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
99$_ = '' if /CURLOPT_HTTP_VERSION/
100$_ = '' if /CURLOPT_INTERLEAVEDATA/
101# CURL_DOES_CONVERSION generates an extra comment.
102$_ = '' if /\/\* "value" \*\//
103</stripfile>
104<file name="%LOGDIR/test%TESTNUMBER.c" mode="text">
105/********* Sample code generated by the curl command line tool **********
106 * All curl_easy_setopt() options are documented at:
107 * https://curl.se/libcurl/c/curl_easy_setopt.html
108 ************************************************************************/
109#include <curl/curl.h>
110
111int main(int argc, char *argv[])
112{
113  CURLcode ret;
114  CURL *hnd;
115  curl_mime *mime1;
116  curl_mimepart *part1;
117  curl_mime *mime2;
118  curl_mimepart *part2;
119  struct curl_slist *slist1;
120
121  mime1 = NULL;
122  mime2 = NULL;
123  slist1 = NULL;
124  slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
125  slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
126
127  hnd = curl_easy_init();
128  curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
129  curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER");
130  mime1 = curl_mime_init(hnd);
131  part1 = curl_mime_addpart(mime1);
132  curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
133  curl_mime_name(part1, "name");
134  part1 = curl_mime_addpart(mime1);
135  mime2 = curl_mime_init(hnd);
136  part2 = curl_mime_addpart(mime2);
137  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
138  part2 = curl_mime_addpart(mime2);
139  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
140  curl_mime_encoder(part2, "8bit");
141  curl_mime_type(part2, "magic/content");
142  part2 = curl_mime_addpart(mime2);
143  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
144  curl_mime_headers(part2, slist1, 1);
145  slist1 = NULL;
146  curl_mime_subparts(part1, mime2);
147  mime2 = NULL;
148  curl_mime_name(part1, "file");
149  curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
150  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
151  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
152  curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
153%if ftp
154  curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
155%endif
156  curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
157
158  /* Here is a list of options the curl code used that cannot get generated
159     as source easily. You may choose to either not use them or implement
160     them yourself.
161
162  CURLOPT_WRITEDATA was set to an object pointer
163  CURLOPT_WRITEFUNCTION was set to a function pointer
164  CURLOPT_READDATA was set to an object pointer
165  CURLOPT_READFUNCTION was set to a function pointer
166  CURLOPT_SEEKDATA was set to an object pointer
167  CURLOPT_SEEKFUNCTION was set to a function pointer
168  CURLOPT_ERRORBUFFER was set to an object pointer
169  CURLOPT_STDERR was set to an object pointer
170  CURLOPT_DEBUGFUNCTION was set to a function pointer
171  CURLOPT_DEBUGDATA was set to an object pointer
172  CURLOPT_HEADERFUNCTION was set to a function pointer
173  CURLOPT_HEADERDATA was set to an object pointer
174
175  */
176
177  ret = curl_easy_perform(hnd);
178
179  curl_easy_cleanup(hnd);
180  hnd = NULL;
181  curl_mime_free(mime1);
182  mime1 = NULL;
183  curl_mime_free(mime2);
184  mime2 = NULL;
185  curl_slist_free_all(slist1);
186  slist1 = NULL;
187
188  return (int)ret;
189}
190/**** End of sample code ****/
191</file>
192</verify>
193</testcase>
194