lib1945.c 2.5 KB

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