113498266Sopenharmony_ci<testcase>
213498266Sopenharmony_ci# Based on test 1315
313498266Sopenharmony_ci<info>
413498266Sopenharmony_ci<keywords>
513498266Sopenharmony_ciHTTP
613498266Sopenharmony_ciHTTP FORMPOST
713498266Sopenharmony_ciHTTP file upload
813498266Sopenharmony_ci--libcurl
913498266Sopenharmony_ci</keywords>
1013498266Sopenharmony_ci</info>
1113498266Sopenharmony_ci
1213498266Sopenharmony_ci# Server-side
1313498266Sopenharmony_ci<reply>
1413498266Sopenharmony_ci<data>
1513498266Sopenharmony_ciHTTP/1.1 200 OK
1613498266Sopenharmony_ciDate: Thu, 29 Jul 2008 14:49:00 GMT
1713498266Sopenharmony_ciServer: test-server/fake
1813498266Sopenharmony_ciContent-Length: 0
1913498266Sopenharmony_ciConnection: close
2013498266Sopenharmony_ci
2113498266Sopenharmony_ci</data>
2213498266Sopenharmony_ci</reply>
2313498266Sopenharmony_ci
2413498266Sopenharmony_ci# Client-side
2513498266Sopenharmony_ci<client>
2613498266Sopenharmony_ci<features>
2713498266Sopenharmony_ciMime
2813498266Sopenharmony_ci</features>
2913498266Sopenharmony_ci<server>
3013498266Sopenharmony_cihttp
3113498266Sopenharmony_ci</server>
3213498266Sopenharmony_ci<name>
3313498266Sopenharmony_ci--libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder
3413498266Sopenharmony_ci</name>
3513498266Sopenharmony_ci<setenv>
3613498266Sopenharmony_ciSSL_CERT_FILE=
3713498266Sopenharmony_ci</setenv>
3813498266Sopenharmony_ci<command>
3913498266Sopenharmony_cihttp://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER -F name=value -F 'file=@%LOGDIR/test%TESTNUMBER.txt,%LOGDIR/test%TESTNUMBER.txt;type=magic/content;encoder=8bit,%LOGDIR/test%TESTNUMBER.txt;headers=X-testheader-1: header 1;headers=X-testheader-2: header 2' --libcurl %LOGDIR/test%TESTNUMBER.c
4013498266Sopenharmony_ci</command>
4113498266Sopenharmony_ci# We create this file before the command is invoked!
4213498266Sopenharmony_ci<file name="%LOGDIR/test%TESTNUMBER.txt">
4313498266Sopenharmony_cidummy data
4413498266Sopenharmony_ci</file>
4513498266Sopenharmony_ci</client>
4613498266Sopenharmony_ci
4713498266Sopenharmony_ci# Verify data after the test has been "shot"
4813498266Sopenharmony_ci<verify>
4913498266Sopenharmony_ci<strip>
5013498266Sopenharmony_ci-----+\w+
5113498266Sopenharmony_ci</strip>
5213498266Sopenharmony_ci<protocol>
5313498266Sopenharmony_ciPOST /we/want/%TESTNUMBER HTTP/1.1
5413498266Sopenharmony_ciHost: %HOSTIP:%HTTPPORT
5513498266Sopenharmony_ciUser-Agent: curl/%VERSION
5613498266Sopenharmony_ciAccept: */*
5713498266Sopenharmony_ciContent-Length: 930
5813498266Sopenharmony_ciContent-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
5913498266Sopenharmony_ci
6013498266Sopenharmony_ci------------------------------9ef8d6205763
6113498266Sopenharmony_ciContent-Disposition: form-data; name="name"
6213498266Sopenharmony_ci
6313498266Sopenharmony_civalue
6413498266Sopenharmony_ci------------------------------9ef8d6205763
6513498266Sopenharmony_ciContent-Disposition: form-data; name="file"
6613498266Sopenharmony_ciContent-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
6713498266Sopenharmony_ci
6813498266Sopenharmony_ciContent-Disposition: attachment; filename="test%TESTNUMBER.txt"
6913498266Sopenharmony_ciContent-Type: text/plain
7013498266Sopenharmony_ci
7113498266Sopenharmony_cidummy data
7213498266Sopenharmony_ci
7313498266Sopenharmony_ci------------------------------9ef8d6205763
7413498266Sopenharmony_ciContent-Disposition: attachment; filename="test%TESTNUMBER.txt"
7513498266Sopenharmony_ciContent-Type: magic/content
7613498266Sopenharmony_ciContent-Transfer-Encoding: 8bit
7713498266Sopenharmony_ci
7813498266Sopenharmony_cidummy data
7913498266Sopenharmony_ci
8013498266Sopenharmony_ci------------------------------9ef8d6205763
8113498266Sopenharmony_ciContent-Disposition: attachment; filename="test%TESTNUMBER.txt"
8213498266Sopenharmony_ciContent-Type: text/plain
8313498266Sopenharmony_ciX-testheader-1: header 1
8413498266Sopenharmony_ciX-testheader-2: header 2
8513498266Sopenharmony_ci
8613498266Sopenharmony_cidummy data
8713498266Sopenharmony_ci
8813498266Sopenharmony_ci------------------------------aaaaaaaaaaaa--
8913498266Sopenharmony_ci
9013498266Sopenharmony_ci------------------------------9ef8d6205763--
9113498266Sopenharmony_ci</protocol>
9213498266Sopenharmony_ci<stripfile>
9313498266Sopenharmony_ci# curl's default user-agent varies with version, libraries etc.
9413498266Sopenharmony_cis/(USERAGENT, \")[^\"]+/${1}stripped/
9513498266Sopenharmony_ci# CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
9613498266Sopenharmony_ci# configurations - just ignore them
9713498266Sopenharmony_ci$_ = '' if /CURLOPT_SSL_VERIFYPEER/
9813498266Sopenharmony_ci$_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
9913498266Sopenharmony_ci$_ = '' if /CURLOPT_HTTP_VERSION/
10013498266Sopenharmony_ci$_ = '' if /CURLOPT_INTERLEAVEDATA/
10113498266Sopenharmony_ci# CURL_DOES_CONVERSION generates an extra comment.
10213498266Sopenharmony_ci$_ = '' if /\/\* "value" \*\//
10313498266Sopenharmony_ci</stripfile>
10413498266Sopenharmony_ci<file name="%LOGDIR/test%TESTNUMBER.c" mode="text">
10513498266Sopenharmony_ci/********* Sample code generated by the curl command line tool **********
10613498266Sopenharmony_ci * All curl_easy_setopt() options are documented at:
10713498266Sopenharmony_ci * https://curl.se/libcurl/c/curl_easy_setopt.html
10813498266Sopenharmony_ci ************************************************************************/
10913498266Sopenharmony_ci#include <curl/curl.h>
11013498266Sopenharmony_ci
11113498266Sopenharmony_ciint main(int argc, char *argv[])
11213498266Sopenharmony_ci{
11313498266Sopenharmony_ci  CURLcode ret;
11413498266Sopenharmony_ci  CURL *hnd;
11513498266Sopenharmony_ci  curl_mime *mime1;
11613498266Sopenharmony_ci  curl_mimepart *part1;
11713498266Sopenharmony_ci  curl_mime *mime2;
11813498266Sopenharmony_ci  curl_mimepart *part2;
11913498266Sopenharmony_ci  struct curl_slist *slist1;
12013498266Sopenharmony_ci
12113498266Sopenharmony_ci  mime1 = NULL;
12213498266Sopenharmony_ci  mime2 = NULL;
12313498266Sopenharmony_ci  slist1 = NULL;
12413498266Sopenharmony_ci  slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
12513498266Sopenharmony_ci  slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
12613498266Sopenharmony_ci
12713498266Sopenharmony_ci  hnd = curl_easy_init();
12813498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
12913498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER");
13013498266Sopenharmony_ci  mime1 = curl_mime_init(hnd);
13113498266Sopenharmony_ci  part1 = curl_mime_addpart(mime1);
13213498266Sopenharmony_ci  curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
13313498266Sopenharmony_ci  curl_mime_name(part1, "name");
13413498266Sopenharmony_ci  part1 = curl_mime_addpart(mime1);
13513498266Sopenharmony_ci  mime2 = curl_mime_init(hnd);
13613498266Sopenharmony_ci  part2 = curl_mime_addpart(mime2);
13713498266Sopenharmony_ci  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
13813498266Sopenharmony_ci  part2 = curl_mime_addpart(mime2);
13913498266Sopenharmony_ci  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
14013498266Sopenharmony_ci  curl_mime_encoder(part2, "8bit");
14113498266Sopenharmony_ci  curl_mime_type(part2, "magic/content");
14213498266Sopenharmony_ci  part2 = curl_mime_addpart(mime2);
14313498266Sopenharmony_ci  curl_mime_filedata(part2, "%LOGDIR/test%TESTNUMBER.txt");
14413498266Sopenharmony_ci  curl_mime_headers(part2, slist1, 1);
14513498266Sopenharmony_ci  slist1 = NULL;
14613498266Sopenharmony_ci  curl_mime_subparts(part1, mime2);
14713498266Sopenharmony_ci  mime2 = NULL;
14813498266Sopenharmony_ci  curl_mime_name(part1, "file");
14913498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
15013498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
15113498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
15213498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
15313498266Sopenharmony_ci%if ftp
15413498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
15513498266Sopenharmony_ci%endif
15613498266Sopenharmony_ci  curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
15713498266Sopenharmony_ci
15813498266Sopenharmony_ci  /* Here is a list of options the curl code used that cannot get generated
15913498266Sopenharmony_ci     as source easily. You may choose to either not use them or implement
16013498266Sopenharmony_ci     them yourself.
16113498266Sopenharmony_ci
16213498266Sopenharmony_ci  CURLOPT_WRITEDATA was set to an object pointer
16313498266Sopenharmony_ci  CURLOPT_WRITEFUNCTION was set to a function pointer
16413498266Sopenharmony_ci  CURLOPT_READDATA was set to an object pointer
16513498266Sopenharmony_ci  CURLOPT_READFUNCTION was set to a function pointer
16613498266Sopenharmony_ci  CURLOPT_SEEKDATA was set to an object pointer
16713498266Sopenharmony_ci  CURLOPT_SEEKFUNCTION was set to a function pointer
16813498266Sopenharmony_ci  CURLOPT_ERRORBUFFER was set to an object pointer
16913498266Sopenharmony_ci  CURLOPT_STDERR was set to an object pointer
17013498266Sopenharmony_ci  CURLOPT_DEBUGFUNCTION was set to a function pointer
17113498266Sopenharmony_ci  CURLOPT_DEBUGDATA was set to an object pointer
17213498266Sopenharmony_ci  CURLOPT_HEADERFUNCTION was set to a function pointer
17313498266Sopenharmony_ci  CURLOPT_HEADERDATA was set to an object pointer
17413498266Sopenharmony_ci
17513498266Sopenharmony_ci  */
17613498266Sopenharmony_ci
17713498266Sopenharmony_ci  ret = curl_easy_perform(hnd);
17813498266Sopenharmony_ci
17913498266Sopenharmony_ci  curl_easy_cleanup(hnd);
18013498266Sopenharmony_ci  hnd = NULL;
18113498266Sopenharmony_ci  curl_mime_free(mime1);
18213498266Sopenharmony_ci  mime1 = NULL;
18313498266Sopenharmony_ci  curl_mime_free(mime2);
18413498266Sopenharmony_ci  mime2 = NULL;
18513498266Sopenharmony_ci  curl_slist_free_all(slist1);
18613498266Sopenharmony_ci  slist1 = NULL;
18713498266Sopenharmony_ci
18813498266Sopenharmony_ci  return (int)ret;
18913498266Sopenharmony_ci}
19013498266Sopenharmony_ci/**** End of sample code ****/
19113498266Sopenharmony_ci</file>
19213498266Sopenharmony_ci</verify>
19313498266Sopenharmony_ci</testcase>
194