lib1940.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. static const char *show[]={
  27. "daTE",
  28. "Server",
  29. "content-type",
  30. "content-length",
  31. "location",
  32. "set-cookie",
  33. "silly-thing",
  34. "fold",
  35. NULL
  36. };
  37. #ifdef LIB1946
  38. #define HEADER_REQUEST 0
  39. #else
  40. #define HEADER_REQUEST -1
  41. #endif
  42. static void showem(CURL *easy, unsigned int type)
  43. {
  44. int i;
  45. struct curl_header *header;
  46. for(i = 0; show[i]; i++) {
  47. if(CURLHE_OK == curl_easy_header(easy, show[i], 0, type, HEADER_REQUEST,
  48. &header)) {
  49. if(header->amount > 1) {
  50. /* more than one, iterate over them */
  51. size_t index = 0;
  52. size_t amount = header->amount;
  53. do {
  54. printf("- %s == %s (%u/%u)\n", header->name, header->value,
  55. (int)index, (int)amount);
  56. if(++index == amount)
  57. break;
  58. if(CURLHE_OK != curl_easy_header(easy, show[i], index, type,
  59. HEADER_REQUEST, &header))
  60. break;
  61. } while(1);
  62. }
  63. else {
  64. /* only one of this */
  65. printf(" %s == %s\n", header->name, header->value);
  66. }
  67. }
  68. }
  69. }
  70. static size_t write_cb(char *data, size_t n, size_t l, void *userp)
  71. {
  72. /* take care of the data here, ignored in this example */
  73. (void)data;
  74. (void)userp;
  75. return n*l;
  76. }
  77. int test(char *URL)
  78. {
  79. CURL *easy;
  80. curl_global_init(CURL_GLOBAL_DEFAULT);
  81. easy = curl_easy_init();
  82. if(easy) {
  83. CURLcode res;
  84. curl_easy_setopt(easy, CURLOPT_URL, URL);
  85. curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  86. curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
  87. /* ignores any content */
  88. curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
  89. /* if there's a proxy set, use it */
  90. if(libtest_arg2 && *libtest_arg2) {
  91. curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
  92. curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
  93. }
  94. res = curl_easy_perform(easy);
  95. if(res) {
  96. printf("badness: %d\n", (int)res);
  97. }
  98. showem(easy, CURLH_HEADER);
  99. if(libtest_arg2 && *libtest_arg2) {
  100. /* now show connect headers only */
  101. showem(easy, CURLH_CONNECT);
  102. }
  103. showem(easy, CURLH_1XX);
  104. showem(easy, CURLH_TRAILER);
  105. curl_easy_cleanup(easy);
  106. }
  107. curl_global_cleanup();
  108. return 0;
  109. }