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