test1404 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. HTTP RFC1867-type formposting - -F with three files, one with explicit type
  28. </name>
  29. <command>
  30. http://%HOSTIP:%HTTPPORT/we/want/1404 -F name=value -F 'file=@log/test1404.txt,log/test1404.txt;type=magic/content,log/test1404.txt' --libcurl log/test1404.c
  31. </command>
  32. # We create this file before the command is invoked!
  33. <file name="log/test1404.txt">
  34. dummy data
  35. </file>
  36. </client>
  37. # Verify data after the test has been "shot"
  38. <verify>
  39. <strip>
  40. (^User-Agent:.*|-----+\w+)
  41. </strip>
  42. <protocol>
  43. POST /we/want/1404 HTTP/1.1
  44. User-Agent: curl/7.18.2 (i686-pc-linux-gnu) libcurl/7.18.2 OpenSSL/0.9.7a ipv6 zlib/1.1.4
  45. Host: %HOSTIP:%HTTPPORT
  46. Accept: */*
  47. Content-Length: 795
  48. Expect: 100-continue
  49. Content-Type: multipart/form-data; boundary=----------------------------9ef8d6205763
  50. ------------------------------9ef8d6205763
  51. Content-Disposition: form-data; name="name"
  52. value
  53. ------------------------------9ef8d6205763
  54. Content-Disposition: form-data; name="file"
  55. Content-Type: multipart/mixed; boundary=----------------------------aaaaaaaaaaaa
  56. Content-Disposition: attachment; filename="test1404.txt"
  57. Content-Type: text/plain
  58. dummy data
  59. ------------------------------9ef8d6205763
  60. Content-Disposition: attachment; filename="test1404.txt"
  61. Content-Type: magic/content
  62. dummy data
  63. ------------------------------9ef8d6205763
  64. Content-Disposition: attachment; filename="test1404.txt"
  65. Content-Type: text/plain
  66. dummy data
  67. ------------------------------aaaaaaaaaaaa--
  68. ------------------------------9ef8d6205763--
  69. </protocol>
  70. <stripfile>
  71. # curl's default user-agent varies with version, libraries etc.
  72. s/(USERAGENT, \")[^\"]+/${1}stripped/
  73. # CURLOPT_SSL_VERIFYPEER and SSH_KNOWNHOSTS vary with configurations - just
  74. # ignore them
  75. $_ = '' if /CURLOPT_SSL_VERIFYPEER/
  76. $_ = '' if /CURLOPT_SSH_KNOWNHOSTS/
  77. </stripfile>
  78. <file name="log/test1404.c" mode="text">
  79. /********* Sample code generated by the curl command line tool **********
  80. * All curl_easy_setopt() options are documented at:
  81. * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
  82. ************************************************************************/
  83. #include <curl/curl.h>
  84. int main(int argc, char *argv[])
  85. {
  86. CURLcode ret;
  87. CURL *hnd;
  88. struct curl_httppost *post1;
  89. struct curl_httppost *postend;
  90. post1 = NULL;
  91. postend = NULL;
  92. curl_formadd(&post1, &postend,
  93. CURLFORM_COPYNAME, "name",
  94. CURLFORM_COPYCONTENTS, "value",
  95. CURLFORM_END);
  96. curl_formadd(&post1, &postend,
  97. CURLFORM_COPYNAME, "file",
  98. CURLFORM_FILE, "log/test1404.txt",
  99. CURLFORM_CONTENTTYPE, "text/plain",
  100. CURLFORM_FILE, "log/test1404.txt",
  101. CURLFORM_CONTENTTYPE, "magic/content",
  102. CURLFORM_FILE, "log/test1404.txt",
  103. CURLFORM_CONTENTTYPE, "text/plain",
  104. CURLFORM_END);
  105. hnd = curl_easy_init();
  106. curl_easy_setopt(hnd, CURLOPT_URL, "http://%HOSTIP:%HTTPPORT/we/want/1404");
  107. curl_easy_setopt(hnd, CURLOPT_HEADER, 1L);
  108. curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
  109. curl_easy_setopt(hnd, CURLOPT_USERAGENT, "stripped");
  110. curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
  111. curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L);
  112. curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
  113. /* Here is a list of options the curl code used that cannot get generated
  114. as source easily. You may select to either not use them or implement
  115. them yourself.
  116. CURLOPT_WRITEDATA set to a objectpointer
  117. CURLOPT_WRITEFUNCTION set to a functionpointer
  118. CURLOPT_READDATA set to a objectpointer
  119. CURLOPT_READFUNCTION set to a functionpointer
  120. CURLOPT_SEEKDATA set to a objectpointer
  121. CURLOPT_SEEKFUNCTION set to a functionpointer
  122. CURLOPT_ERRORBUFFER set to a objectpointer
  123. CURLOPT_STDERR set to a objectpointer
  124. CURLOPT_DEBUGFUNCTION set to a functionpointer
  125. CURLOPT_DEBUGDATA set to a objectpointer
  126. CURLOPT_HEADERFUNCTION set to a functionpointer
  127. CURLOPT_HEADERDATA set to a objectpointer
  128. */
  129. ret = curl_easy_perform(hnd);
  130. curl_easy_cleanup(hnd);
  131. hnd = NULL;
  132. curl_formfree(post1);
  133. post1 = NULL;
  134. return (int)ret;
  135. }
  136. /**** End of sample code ****/
  137. </file>
  138. </verify>
  139. </testcase>