lib1940.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. "blank",
  36. "Blank2",
  37. NULL
  38. };
  39. #ifdef LIB1946
  40. #define HEADER_REQUEST 0
  41. #else
  42. #define HEADER_REQUEST -1
  43. #endif
  44. static void showem(CURL *easy, unsigned int type)
  45. {
  46. int i;
  47. struct curl_header *header;
  48. for(i = 0; show[i]; i++) {
  49. if(CURLHE_OK == curl_easy_header(easy, show[i], 0, type, HEADER_REQUEST,
  50. &header)) {
  51. if(header->amount > 1) {
  52. /* more than one, iterate over them */
  53. size_t index = 0;
  54. size_t amount = header->amount;
  55. do {
  56. printf("- %s == %s (%u/%u)\n", header->name, header->value,
  57. (int)index, (int)amount);
  58. if(++index == amount)
  59. break;
  60. if(CURLHE_OK != curl_easy_header(easy, show[i], index, type,
  61. HEADER_REQUEST, &header))
  62. break;
  63. } while(1);
  64. }
  65. else {
  66. /* only one of this */
  67. printf(" %s == %s\n", header->name, header->value);
  68. }
  69. }
  70. }
  71. }
  72. static size_t write_cb(char *data, size_t n, size_t l, void *userp)
  73. {
  74. /* take care of the data here, ignored in this example */
  75. (void)data;
  76. (void)userp;
  77. return n*l;
  78. }
  79. CURLcode test(char *URL)
  80. {
  81. CURL *easy = NULL;
  82. CURLcode res = CURLE_OK;
  83. global_init(CURL_GLOBAL_DEFAULT);
  84. easy_init(easy);
  85. easy_setopt(easy, CURLOPT_URL, URL);
  86. easy_setopt(easy, CURLOPT_VERBOSE, 1L);
  87. easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
  88. /* ignores any content */
  89. easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
  90. /* if there's a proxy set, use it */
  91. if(libtest_arg2 && *libtest_arg2) {
  92. easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
  93. easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
  94. }
  95. res = curl_easy_perform(easy);
  96. if(res)
  97. goto test_cleanup;
  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. test_cleanup:
  106. curl_easy_cleanup(easy);
  107. curl_global_cleanup();
  108. return res;
  109. }