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 three files, one with explicit type 31 </name> 32 <command> 33http://%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"> 37dummy 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> 47POST /we/want/1404 HTTP/1.1 48User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.7a ipv6 zlib/1.1.4 49Host: %HOSTIP:%HTTPPORT 50Accept: */* 51Content-Length: 795 52Expect: 100-continue 53Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763 54 55------------------------------9ef8d6205763 56Content-Disposition: form-data; name="name" 57 58value 59------------------------------9ef8d6205763 60Content-Disposition: form-data; name="file" 61Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa 62 63Content-Disposition: attachment; filename="test1404.txt" 64Content-Type: text/plain 65 66dummy data 67 68------------------------------9ef8d6205763 69Content-Disposition: attachment; filename="test1404.txt" 70Content-Type: magic/content 71 72dummy data 73 74------------------------------9ef8d6205763 75Content-Disposition: attachment; filename="test1404.txt" 76Content-Type: text/plain 77 78dummy data 79 80------------------------------aaaaaaaaaaaa-- 81------------------------------9ef8d6205763-- 82</protocol> 83<stripfile> 84# curl's default user-agent varies with version, libraries etc. 85s/(USERAGENT, \")[^\"]+/${1}stripped/ 86# CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just 87# ignore them 88$_ = '' if /CURLOPT_SSL_VERIFYPEER/ 89$_ = '' if /CURLOPT_SSH_KNOWNHOSTS/ 90</stripfile> 91<file name="log/test1404.c" mode="text"> 92/********* Sample code generated by the curl command line tool ********** 93 * All curl_easy_setopt() options are documented at: 94 * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html 95 ************************************************************************/ 96#include <curl/curl.h> 97 98int main(int argc, char *argv[]) 99{ 100 CURLcode ret; 101 CURL *hnd; 102 struct curl_httppost *post1; 103 struct curl_httppost *postend; 104 105 post1 = NULL; 106 postend = NULL; 107 curl_formadd(&post1, &postend, 108 CURLFORM_COPYNAME, "name", 109 CURLFORM_COPYCONTENTS, "value", 110 CURLFORM_END); 111 curl_formadd(&post1, &postend, 112 CURLFORM_COPYNAME, "file", 113 CURLFORM_FILE, "log/test1404.txt", 114 CURLFORM_CONTENTTYPE, "text/plain", 115 CURLFORM_FILE, "log/test1404.txt", 116 CURLFORM_CONTENTTYPE, "magic/content", 117 CURLFORM_FILE, "log/test1404.txt", 118 CURLFORM_CONTENTTYPE, "text/plain", 119 CURLFORM_END); 120 121 hnd = curl_easy_init(); 122 curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404"); 123 curl_easy_setopt(hnd, CURLOPT_HEADER, 1L); 124 curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1); 125 curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped"); 126 curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); 127 curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); 128 curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L); 129 130 /* Here is a list of options the curl code used that cannot get generated 131 as source easily. You may select to either not use them or implement 132 them yourself. 133 134 CURLOPT_WRITEDATA set to a objectpointer 135 CURLOPT_WRITEFUNCTION set to a functionpointer 136 CURLOPT_READDATA set to a objectpointer 137 CURLOPT_READFUNCTION set to a functionpointer 138 CURLOPT_SEEKDATA set to a objectpointer 139 CURLOPT_SEEKFUNCTION set to a functionpointer 140 CURLOPT_ERRORBUFFER set to a objectpointer 141 CURLOPT_STDERR set to a objectpointer 142 CURLOPT_DEBUGFUNCTION set to a functionpointer 143 CURLOPT_DEBUGDATA set to a objectpointer 144 CURLOPT_HEADERFUNCTION set to a functionpointer 145 CURLOPT_HEADERDATA set to a objectpointer 146 147 */ 148 149 ret = curl_easy_perform(hnd); 150 151 curl_easy_cleanup(hnd); 152 hnd = NULL; 153 curl_formfree(post1); 154 post1 = NULL; 155 156 return (int)ret; 157} 158/**** End of sample code ****/ 159</file> 160</verify> 161</testcase> 162