test1404 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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/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
  34. </command>
  35. # We create this file before the command is invoked!
  36. <file name="log/test1404.txt">
  37. dummy data
  38. </file>
  39. </client>
  40. # Verify data after the test has been "shot"
  41. <verify>
  42. <strip>
  43. (^User-Agent:.*|-----+\w+)
  44. </strip>
  45. <protocol>
  46. POST /we/want/1404 HTTP/1.1
  47. User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.7a ipv6 zlib/1.1.4
  48. Host: %HOSTIP:%HTTPPORT
  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="test1404.txt"
  59. Content-Type: text/plain
  60. dummy data
  61. ------------------------------9ef8d6205763
  62. Content-Disposition: attachment; filename="test1404.txt"
  63. Content-Type: magic/content
  64. Content-Transfer-Encoding: 8bit
  65. dummy data
  66. ------------------------------9ef8d6205763
  67. Content-Disposition: attachment; filename="test1404.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. </stripfile>
  84. <file name="log/test1404.c" mode="text">
  85. /********* Sample code generated by the curl command line tool **********
  86. * All curl_easy_setopt() options are documented at:
  87. * https://curl.haxx.se/libcurl/c/curl_easy_setopt.html
  88. ************************************************************************/
  89. #include <curl/curl.h>
  90. int main(int argc, char *argv[])
  91. {
  92. CURLcode ret;
  93. CURL *hnd;
  94. curl_mime *mime1;
  95. curl_mimepart *part1;
  96. curl_mime *mime2;
  97. curl_mimepart *part2;
  98. struct curl_slist *slist1;
  99. mime1 = NULL;
  100. mime2 = NULL;
  101. slist1 = NULL;
  102. slist1 = curl_slist_append(slist1, "X-testheader-1: header 1");
  103. slist1 = curl_slist_append(slist1, "X-testheader-2: header 2");
  104. hnd = curl_easy_init();
  105. curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L);
  106. curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404");
  107. mime1 = curl_mime_init(hnd);
  108. part1 = curl_mime_addpart(mime1);
  109. curl_mime_data(part1, "value", CURL_ZERO_TERMINATED);
  110. curl_mime_name(part1, "name");
  111. part1 = curl_mime_addpart(mime1);
  112. mime2 = curl_mime_init(hnd);
  113. part2 = curl_mime_addpart(mime2);
  114. curl_mime_filedata(part2, "log/test1404.txt");
  115. part2 = curl_mime_addpart(mime2);
  116. curl_mime_filedata(part2, "log/test1404.txt");
  117. curl_mime_encoder(part2, "8bit");
  118. curl_mime_type(part2, "magic/content");
  119. part2 = curl_mime_addpart(mime2);
  120. curl_mime_filedata(part2, "log/test1404.txt");
  121. curl_mime_headers(part2, slist1, 1);
  122. slist1 = NULL;
  123. curl_mime_subparts(part1, mime2);
  124. mime2 = NULL;
  125. curl_mime_name(part1, "file");
  126. curl_easy_setopt(hnd, CURLOPT_MIMEPOST, mime1);
  127. curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
  128. curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  129. curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
  130. curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
  131. /* Here is a list of options the curl code used that cannot get generated
  132. as source easily. You may select to either not use them or implement
  133. them yourself.
  134. CURLOPT_WRITEDATA set to a objectpointer
  135. CURLOPT_INTERLEAVEDATA set to a objectpointer
  136. CURLOPT_WRITEFUNCTION set to a functionpointer
  137. CURLOPT_READDATA set to a objectpointer
  138. CURLOPT_READFUNCTION set to a functionpointer
  139. CURLOPT_SEEKDATA set to a objectpointer
  140. CURLOPT_SEEKFUNCTION set to a functionpointer
  141. CURLOPT_ERRORBUFFER set to a objectpointer
  142. CURLOPT_STDERR set to a objectpointer
  143. CURLOPT_DEBUGFUNCTION set to a functionpointer
  144. CURLOPT_DEBUGDATA set to a objectpointer
  145. CURLOPT_HEADERFUNCTION set to a functionpointer
  146. CURLOPT_HEADERDATA set to a objectpointer
  147. */
  148. ret = curl_easy_perform(hnd);
  149. curl_easy_cleanup(hnd);
  150. hnd = NULL;
  151. curl_mime_free(mime1);
  152. mime1 = NULL;
  153. curl_mime_free(mime2);
  154. mime2 = NULL;
  155. curl_slist_free_all(slist1);
  156. slist1 = NULL;
  157. return (int)ret;
  158. }
  159. /**** End of sample code ****/
  160. </file>
  161. </verify>
  162. </testcase>