lib1945.c 2.5 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. int test(char *URL)
  48. {
  49. CURL *easy;
  50. curl_global_init(CURL_GLOBAL_DEFAULT);
  51. easy = curl_easy_init();
  52. if(easy) {
  53. CURLcode res;
  54. curl_easy_setopt(easy, CURLOPT_URL, URL);
  55. curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  56. curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
  57. /* ignores any content */
  58. curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
  59. /* if there's a proxy set, use it */
  60. if(libtest_arg2 && *libtest_arg2) {
  61. curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
  62. curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
  63. }
  64. res = curl_easy_perform(easy);
  65. if(res) {
  66. printf("badness: %d\n", (int)res);
  67. }
  68. showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
  69. curl_easy_cleanup(easy);
  70. }
  71. curl_global_cleanup();
  72. return 0;
  73. }