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