lib1525.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  9. * Copyright (C) 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 https://curl.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. * SPDX-License-Identifier: curl
  23. *
  24. ***************************************************************************/
  25. /*
  26. * This unit test PUT http data over proxy. Proxy header will be different
  27. * from server http header
  28. */
  29. #include "test.h"
  30. #include "memdebug.h"
  31. static char data [] = "Hello Cloud!\n";
  32. static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
  33. {
  34. size_t amount = nmemb * size; /* Total bytes curl wants */
  35. if(amount < strlen(data)) {
  36. return strlen(data);
  37. }
  38. (void)stream;
  39. memcpy(ptr, data, strlen(data));
  40. return strlen(data);
  41. }
  42. int test(char *URL)
  43. {
  44. CURL *curl = NULL;
  45. CURLcode res = CURLE_FAILED_INIT;
  46. /* http and proxy header list */
  47. struct curl_slist *hhl = NULL;
  48. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  49. fprintf(stderr, "curl_global_init() failed\n");
  50. return TEST_ERR_MAJOR_BAD;
  51. }
  52. curl = curl_easy_init();
  53. if(!curl) {
  54. fprintf(stderr, "curl_easy_init() failed\n");
  55. curl_global_cleanup();
  56. return TEST_ERR_MAJOR_BAD;
  57. }
  58. hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
  59. if(!hhl) {
  60. goto test_cleanup;
  61. }
  62. test_setopt(curl, CURLOPT_URL, URL);
  63. test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
  64. test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
  65. test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
  66. test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
  67. test_setopt(curl, CURLOPT_POST, 0L);
  68. test_setopt(curl, CURLOPT_UPLOAD, 1L);
  69. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  70. test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
  71. test_setopt(curl, CURLOPT_HEADER, 1L);
  72. test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
  73. test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
  74. test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
  75. test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(data));
  76. res = curl_easy_perform(curl);
  77. test_cleanup:
  78. curl_easy_cleanup(curl);
  79. curl_slist_free_all(hhl);
  80. curl_global_cleanup();
  81. return (int)res;
  82. }