xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 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 | <features> |
| 27 | Mime |
| 28 | </features> |
| 29 | <server> |
| 30 | http |
| 31 | </server> |
| 32 | <name> |
| 33 | --libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder |
| 34 | </name> |
| 35 | <setenv> |
| 36 | SSL_CERT_FILE= |
| 37 | </setenv> |
| 38 | <command> |
| 39 | http://%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 |
| 40 | </command> |
| 41 | # We create this file before the command is invoked! |
| 42 | <file name="log/test%TESTNUMBER.txt"> |
| 43 | dummy 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> |
| 53 | POST /we/want/%TESTNUMBER HTTP/1.1
|
| 54 | Host: %HOSTIP:%HTTPPORT
|
| 55 | User-Agent: curl/%VERSION
|
| 56 | Accept: */*
|
| 57 | Content-Length: 882
|
| 58 | Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
|
| 59 |
|
| 60 | ------------------------------9ef8d6205763
|
| 61 | Content-Disposition: form-data; name="name"
|
| 62 |
|
| 63 | value
|
| 64 | ------------------------------9ef8d6205763
|
| 65 | Content-Disposition: form-data; name="file"
|
| 66 | Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
|
| 67 |
|
| 68 | Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
|
| 69 | Content-Type: text/plain
|
| 70 |
|
| 71 | dummy data |
| 72 |
|
| 73 | ------------------------------9ef8d6205763
|
| 74 | Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
|
| 75 | Content-Type: magic/content
|
| 76 | Content-Transfer-Encoding: 8bit
|
| 77 |
|
| 78 | dummy data |
| 79 |
|
| 80 | ------------------------------9ef8d6205763
|
| 81 | Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
|
| 82 | Content-Type: text/plain
|
| 83 | X-testheader-1: header 1
|
| 84 | X-testheader-2: header 2
|
| 85 |
|
| 86 | dummy data |
| 87 |
|
| 88 | ------------------------------aaaaaaaaaaaa--
|
| 89 |
|
| 90 | ------------------------------9ef8d6205763--
|
| 91 | </protocol> |
| 92 | <stripfile> |
| 93 | # curl's default user-agent varies with version, libraries etc. |
| 94 | s/(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="log/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 | |
| 111 | int 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, "log/test%TESTNUMBER.txt"); |
| 138 | part2 = curl_mime_addpart(mime2); |
| 139 | curl_mime_filedata(part2, "log/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, "log/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> |