lib1525.c 2.9 KB

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