2
0

lib1945.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 https://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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "test.h"
  25. #include "memdebug.h"
  26. #ifdef _MSC_VER
  27. /* warning C4706: assignment within conditional expression */
  28. #pragma warning(disable:4706)
  29. #endif
  30. static void showem(CURL *easy, unsigned int type)
  31. {
  32. struct curl_header *header = NULL;
  33. struct curl_header *prev = NULL;
  34. while((header = curl_easy_nextheader(easy, type, 0, prev))) {
  35. printf(" %s == %s (%u/%u)\n", header->name, header->value,
  36. (int)header->index, (int)header->amount);
  37. prev = header;
  38. }
  39. }
  40. static size_t write_cb(char *data, size_t n, size_t l, void *userp)
  41. {
  42. /* take care of the data here, ignored in this example */
  43. (void)data;
  44. (void)userp;
  45. return n*l;
  46. }
  47. CURLcode test(char *URL)
  48. {
  49. CURL *easy;
  50. CURLcode res = CURLE_OK;
  51. global_init(CURL_GLOBAL_DEFAULT);
  52. easy_init(easy);
  53. curl_easy_setopt(easy, CURLOPT_URL, URL);
  54. curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  55. curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
  56. /* ignores any content */
  57. curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
  58. /* if there's a proxy set, use it */
  59. if(libtest_arg2 && *libtest_arg2) {
  60. curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
  61. curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
  62. }
  63. res = curl_easy_perform(easy);
  64. if(res) {
  65. printf("badness: %d\n", res);
  66. }
  67. showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
  68. test_cleanup:
  69. curl_easy_cleanup(easy);
  70. curl_global_cleanup();
  71. return res;
  72. }