Imported Upstream version 7.48.0
[platform/upstream/curl.git] / tests / data / test1404
1 <testcase>
2 # Based on test 1315
3 <info>
4 <keywords>
5 HTTP
6 HTTP FORMPOST
7 HTTP file upload
8 --libcurl
9 </keywords>
10 </info>
11
12 # Server-side
13 <reply>
14 <data>
15 HTTP/1.1 200 OK
16 Date: Thu, 29 Jul 2008 14:49:00 GMT
17 Server: test-server/fake
18 Content-Length: 0
19 Connection: close
20
21 </data>
22 </reply>
23
24 # Client-side
25 <client>
26 <server>
27 http
28 </server>
29  <name>
30 --libcurl for HTTP RFC1867-type formposting - -F with three files, one with explicit type
31  </name>
32  <command>
33 http://%HOSTIP:%HTTPPORT/we/want/1404 -F name=value -F 'file=@log/test1404.txt,log/test1404.txt;type=magic/content,log/test1404.txt' --libcurl log/test1404.c
34 </command>
35 # We create this file before the command is invoked!
36 <file name="log/test1404.txt">
37 dummy data
38 </file>
39 </client>
40
41 # Verify data after the test has been "shot"
42 <verify>
43 <strip>
44 (^User-Agent:.*|-----+\w+)
45 </strip>
46 <protocol>
47 POST /we/want/1404 HTTP/1.1\r
48 User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.7a ipv6 zlib/1.1.4\r
49 Host: %HOSTIP:%HTTPPORT\r
50 Accept: */*\r
51 Content-Length: 795\r
52 Expect: 100-continue\r
53 Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763\r
54 \r
55 ------------------------------9ef8d6205763\r
56 Content-Disposition: form-data; name="name"\r
57 \r
58 value\r
59 ------------------------------9ef8d6205763\r
60 Content-Disposition: form-data; name="file"\r
61 Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa\r
62 \r
63 Content-Disposition: attachment; filename="test1404.txt"\r
64 Content-Type: text/plain\r
65 \r
66 dummy data
67 \r
68 ------------------------------9ef8d6205763\r
69 Content-Disposition: attachment; filename="test1404.txt"\r
70 Content-Type: magic/content\r
71 \r
72 dummy data
73 \r
74 ------------------------------9ef8d6205763\r
75 Content-Disposition: attachment; filename="test1404.txt"\r
76 Content-Type: text/plain\r
77 \r
78 dummy data
79 \r
80 ------------------------------aaaaaaaaaaaa--\r
81 ------------------------------9ef8d6205763--\r
82 </protocol>
83 <stripfile>
84 # curl's default user-agent varies with version, libraries etc.
85 s/(USERAGENT, \")[^\"]+/${1}stripped/
86 # CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
87 # configurations - just ignore them
88 $_ = '' if /CURLOPT_SSL_VERIFYPEER/
89 $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
90 $_ = '' if /CURLOPT_HTTP_VERSION/
91 </stripfile>
92 <file name="log/test1404.c" mode="text">
93 /********* Sample code generated by the curl command line tool **********
94  * All curl_easy_setopt() options are documented at:
95  * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
96  ************************************************************************/
97 #include <curl/curl.h>
98
99 int main(int argc, char *argv[])
100 {
101   CURLcode ret;
102   CURL *hnd;
103   struct curl_httppost *post1;
104   struct curl_httppost *postend;
105
106   post1 = NULL;
107   postend = NULL;
108   curl_formadd(&post1, &postend,
109                CURLFORM_COPYNAME, "name",
110                CURLFORM_COPYCONTENTS, "value",
111                CURLFORM_END);
112   curl_formadd(&post1, &postend,
113                CURLFORM_COPYNAME, "file",
114                CURLFORM_FILE, "log/test1404.txt",
115                CURLFORM_CONTENTTYPE, "text/plain",
116                CURLFORM_FILE, "log/test1404.txt",
117                CURLFORM_CONTENTTYPE, "magic/content",
118                CURLFORM_FILE, "log/test1404.txt",
119                CURLFORM_CONTENTTYPE, "text/plain",
120                CURLFORM_END);
121
122   hnd = curl_easy_init();
123   curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404");
124   curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
125   curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
126   curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
127   curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
128   curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
129   curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
130
131   /* Here is a list of options the curl code used that cannot get generated
132      as source easily. You may select to either not use them or implement
133      them yourself.
134
135   CURLOPT_WRITEDATA set to a objectpointer
136   CURLOPT_WRITEFUNCTION set to a functionpointer
137   CURLOPT_READDATA set to a objectpointer
138   CURLOPT_READFUNCTION set to a functionpointer
139   CURLOPT_SEEKDATA set to a objectpointer
140   CURLOPT_SEEKFUNCTION set to a functionpointer
141   CURLOPT_ERRORBUFFER set to a objectpointer
142   CURLOPT_STDERR set to a objectpointer
143   CURLOPT_DEBUGFUNCTION set to a functionpointer
144   CURLOPT_DEBUGDATA set to a objectpointer
145   CURLOPT_HEADERFUNCTION set to a functionpointer
146   CURLOPT_HEADERDATA set to a objectpointer
147
148   */
149
150   ret = curl_easy_perform(hnd);
151
152   curl_easy_cleanup(hnd);
153   hnd = NULL;
154   curl_formfree(post1);
155   post1 = NULL;
156
157   return (int)ret;
158 }
159 /**** End of sample code ****/
160 </file>
161 </verify>
162 </testcase>