lib1527.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, Vijay Panghal, <vpanghal@maginatics.com>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /*
  23. * This unit test PUT http data over proxy. Same http header will be generated
  24. * for server and proxy
  25. */
  26. #include "test.h"
  27. #include "memdebug.h"
  28. static char data [] = "Hello Cloud!\n";
  29. static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
  30. {
  31. size_t amount = nmemb * size; /* Total bytes curl wants */
  32. if (amount < strlen(data)) {
  33. return strlen(data);
  34. }
  35. (void)stream;
  36. memcpy(ptr, data, strlen(data));
  37. return strlen(data);
  38. }
  39. int test(char *URL)
  40. {
  41. CURL *curl = NULL;
  42. CURLcode res = CURLE_FAILED_INIT;
  43. /* http header list*/
  44. struct curl_slist *hhl = NULL, *tmp = NULL;
  45. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  46. fprintf(stderr, "curl_global_init() failed\n");
  47. return TEST_ERR_MAJOR_BAD;
  48. }
  49. if((curl = curl_easy_init()) == NULL) {
  50. fprintf(stderr, "curl_easy_init() failed\n");
  51. curl_global_cleanup();
  52. return TEST_ERR_MAJOR_BAD;
  53. }
  54. hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
  55. if (!hhl) {
  56. goto test_cleanup;
  57. }
  58. tmp = curl_slist_append(hhl, "Expect: 100-continue");
  59. if (!tmp) {
  60. goto test_cleanup;
  61. }
  62. hhl = tmp;
  63. test_setopt(curl, CURLOPT_URL, URL);
  64. test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  65. test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
  66. test_setopt(curl, CURLOPT_POST, 0L);
  67. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  68. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  69. test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  70. test_setopt(curl, CURLOPT_HEADER, 1L);
  71. test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
  72. test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  73. test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
  74. test_setopt(curl, CURLOPT_INFILESIZE, strlen(data));
  75. res = curl_easy_perform(curl);
  76. test_cleanup:
  77. curl_easy_cleanup(curl);
  78. curl_slist_free_all(hhl);
  79. curl_global_cleanup();
  80. return (int)res;
  81. }