test1404 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. # Server-side
  12. <reply>
  13. <data>
  14. HTTP/1.1 200 OK
  15. Date: Thu, 29 Jul 2008 14:49:00 GMT
  16. Server: test-server/fake
  17. Content-Length: 0
  18. Connection: close
  19. </data>
  20. </reply>
  21. # Client-side
  22. <client>
  23. <server>
  24. http
  25. </server>
  26. <name>
  27. --libcurl for HTTP RFC1867-type formposting - -F with 3 files, one with explicit type & encoder
  28. </name>
  29. <setenv>
  30. SSL_CERT_FILE=
  31. </setenv>
  32. <command>
  33. 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
  34. </command>
  35. # We create this file before the command is invoked!
  36. <file name="log/test%TESTNUMBER.txt">
  37. dummy data
  38. </file>
  39. </client>
  40. # Verify data after the test has been "shot"
  41. <verify>
  42. <strip>
  43. -----+\w+
  44. </strip>
  45. <protocol>
  46. POST /we/want/%TESTNUMBER HTTP/1.1
  47. Host: %HOSTIP:%HTTPPORT
  48. User-Agent: curl/%VERSION
  49. Accept: */*
  50. Content-Length: 882
  51. Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
  52. ------------------------------9ef8d6205763
  53. Content-Disposition: form-data; name="name"
  54. value
  55. ------------------------------9ef8d6205763
  56. Content-Disposition: form-data; name="file"
  57. Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
  58. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  59. Content-Type: text/plain
  60. dummy data
  61. ------------------------------9ef8d6205763
  62. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  63. Content-Type: magic/content
  64. Content-Transfer-Encoding: 8bit
  65. dummy data
  66. ------------------------------9ef8d6205763
  67. Content-Disposition: attachment; filename="test%TESTNUMBER.txt"
  68. Content-Type: text/plain
  69. X-testheader-1: header 1
  70. X-testheader-2: header 2
  71. dummy data
  72. ------------------------------aaaaaaaaaaaa--
  73. ------------------------------9ef8d6205763--
  74. </protocol>
  75. <stripfile>
  76. # curl's default user-agent varies with version, libraries etc.
  77. s/(USERAGENT, \")[^\"]+/${1}stripped/
  78. # CURLOPT_SSL_VERIFYPEER, SSH_KNOWNHOSTS and HTTP_VERSION vary with
  79. # configurations - just ignore them
  80. $_ = '' if /CURLOPT_SSL_VERIFYPEER/
  81. $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
  82. $_ = '' if /CURLOPT_HTTP_VERSION/
  83. $_ = '' if /CURLOPT_INTERLEAVEDATA/
  84. # CURL_DOES_CONVERSION generates an extra comment.
  85. $_ = '' if /\/\* "value" \*\//
  86. </stripfile>
  87. <file name="log/test%TESTNUMBER.c" mode="text">
  88. /********* Sample code generated by the curl command line tool **********
  89. * All curl_easy_setopt() options are documented at:
  90. * https://curl.se/libcurl/c/curl_easy_setopt.html
  91. ************************************************************************/
  92. #include <curl/curl.h>
  93. int main(int argc, char *argv[])
  94. {
  95. CURLcode ret;
  96. CURL *hnd;
  97. curl_mime *mime1;
  98. curl_mimepart *part1;
  99. curl_mime *mime2;
  100. curl_mimepart *part2;
  101. struct curl_slist *slist1;
  102. mime1 = NULL;
  103. mime2 = NULL;
  104. slist1 = NULL;
  105. slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
  106. slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
  107. hnd = curl_easy_init();
  108. curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  109. curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/%TESTNUMBER");
  110. mime1 = curl_mime_init(hnd);
  111. part1 = curl_mime_addpart(mime1);
  112. curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
  113. curl_mime_name(part1, "name");
  114. part1 = curl_mime_addpart(mime1);
  115. mime2 = curl_mime_init(hnd);
  116. part2 = curl_mime_addpart(mime2);
  117. curl_mime_filedata(part2, "log/test%TESTNUMBER.txt");
  118. part2 = curl_mime_addpart(mime2);
  119. curl_mime_filedata(part2, "log/test%TESTNUMBER.txt");
  120. curl_mime_encoder(part2, "8bit");
  121. curl_mime_type(part2, "magic/content");
  122. part2 = curl_mime_addpart(mime2);
  123. curl_mime_filedata(part2, "log/test%TESTNUMBER.txt");
  124. curl_mime_headers(part2, slist1, 1);
  125. slist1 = NULL;
  126. curl_mime_subparts(part1, mime2);
  127. mime2 = NULL;
  128. curl_mime_name(part1, "file");
  129. curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
  130. curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
  131. curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  132. curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
  133. %if ftp
  134. curl_easy_setopt(hnd, CURLOPT_FTP_SKIP_PASV_IP, 1L);
  135. %endif
  136. curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
  137. /* Here is a list of options the curl code used that cannot get generated
  138. as source easily. You may choose to either not use them or implement
  139. them yourself.
  140. CURLOPT_WRITEDATA set to a objectpointer
  141. CURLOPT_WRITEFUNCTION set to a functionpointer
  142. CURLOPT_READDATA set to a objectpointer
  143. CURLOPT_READFUNCTION set to a functionpointer
  144. CURLOPT_SEEKDATA set to a objectpointer
  145. CURLOPT_SEEKFUNCTION set to a functionpointer
  146. CURLOPT_ERRORBUFFER set to a objectpointer
  147. CURLOPT_STDERR set to a objectpointer
  148. CURLOPT_DEBUGFUNCTION set to a functionpointer
  149. CURLOPT_DEBUGDATA set to a objectpointer
  150. CURLOPT_HEADERFUNCTION set to a functionpointer
  151. CURLOPT_HEADERDATA set to a objectpointer
  152. */
  153. ret = curl_easy_perform(hnd);
  154. curl_easy_cleanup(hnd);
  155. hnd = NULL;
  156. curl_mime_free(mime1);
  157. mime1 = NULL;
  158. curl_mime_free(mime2);
  159. mime2 = NULL;
  160. curl_slist_free_all(slist1);
  161. slist1 = NULL;
  162. return (int)ret;
  163. }
  164. /**** End of sample code ****/
  165. </file>
  166. </verify>
  167. </testcase>