Home | History | Annotate | Download | only in data
      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 # CURL_DOES_CONVERSION generates an extra comment.
     98 $_ = '' if /\/\* "value" \*\//
     99 </stripfile>
    100 <file name="log/test1404.c" mode="text">
    101 /********* Sample code generated by the curl command line tool **********
    102  * All curl_easy_setopt() options are documented at:
    103  * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
    104  ************************************************************************/
    105 #include <curl/curl.h>
    106 
    107 int main(int argc, char *argv[])
    108 {
    109   CURLcode ret;
    110   CURL *hnd;
    111   curl_mime *mime1;
    112   curl_mimepart *part1;
    113   curl_mime *mime2;
    114   curl_mimepart *part2;
    115   struct curl_slist *slist1;
    116 
    117   mime1 = NULL;
    118   mime2 = NULL;
    119   slist1 = NULL;
    120   slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
    121   slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
    122 
    123   hnd = curl_easy_init();
    124   curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
    125   curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404");
    126   mime1 = curl_mime_init(hnd);
    127   part1 = curl_mime_addpart(mime1);
    128   curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
    129   curl_mime_name(part1, "name");
    130   part1 = curl_mime_addpart(mime1);
    131   mime2 = curl_mime_init(hnd);
    132   part2 = curl_mime_addpart(mime2);
    133   curl_mime_filedata(part2, "log/test1404.txt");
    134   part2 = curl_mime_addpart(mime2);
    135   curl_mime_filedata(part2, "log/test1404.txt");
    136   curl_mime_encoder(part2, "8bit");
    137   curl_mime_type(part2, "magic/content");
    138   part2 = curl_mime_addpart(mime2);
    139   curl_mime_filedata(part2, "log/test1404.txt");
    140   curl_mime_headers(part2, slist1, 1);
    141   slist1 = NULL;
    142   curl_mime_subparts(part1, mime2);
    143   mime2 = NULL;
    144   curl_mime_name(part1, "file");
    145   curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
    146   curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
    147   curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
    148   curl_easy_setopt(hnd, CURLOPT_HTTP09_ALLOWED, 1L);
    149   curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
    150   curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
    151 
    152   /* Here is a list of options the curl code used that cannot get generated
    153      as source easily. You may select to either not use them or implement
    154      them yourself.
    155 
    156   CURLOPT_WRITEDATA set to a objectpointer
    157   CURLOPT_INTERLEAVEDATA set to a objectpointer
    158   CURLOPT_WRITEFUNCTION set to a functionpointer
    159   CURLOPT_READDATA set to a objectpointer
    160   CURLOPT_READFUNCTION set to a functionpointer
    161   CURLOPT_SEEKDATA set to a objectpointer
    162   CURLOPT_SEEKFUNCTION set to a functionpointer
    163   CURLOPT_ERRORBUFFER set to a objectpointer
    164   CURLOPT_STDERR set to a objectpointer
    165   CURLOPT_DEBUGFUNCTION set to a functionpointer
    166   CURLOPT_DEBUGDATA set to a objectpointer
    167   CURLOPT_HEADERFUNCTION set to a functionpointer
    168   CURLOPT_HEADERDATA set to a objectpointer
    169 
    170   */
    171 
    172   ret = curl_easy_perform(hnd);
    173 
    174   curl_easy_cleanup(hnd);
    175   hnd = NULL;
    176   curl_mime_free(mime1);
    177   mime1 = NULL;
    178   curl_mime_free(mime2);
    179   mime2 = NULL;
    180   curl_slist_free_all(slist1);
    181   slist1 = NULL;
    182 
    183   return (int)ret;
    184 }
    185 /**** End of sample code ****/
    186 </file>
    187 </verify>
    188 </testcase>
    189