lib1509.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.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 "testutil.h"
  26. #include "warnless.h"
  27. #include "memdebug.h"
  28. size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream);
  29. size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream);
  30. static unsigned long realHeaderSize = 0;
  31. CURLcode test(char *URL)
  32. {
  33. long headerSize;
  34. CURLcode code;
  35. CURL *curl = NULL;
  36. CURLcode res = CURLE_OK;
  37. global_init(CURL_GLOBAL_ALL);
  38. easy_init(curl);
  39. easy_setopt(curl, CURLOPT_PROXY, libtest_arg2); /* set in first.c */
  40. easy_setopt(curl, CURLOPT_WRITEFUNCTION, *WriteOutput);
  41. easy_setopt(curl, CURLOPT_HEADERFUNCTION, *WriteHeader);
  42. easy_setopt(curl, CURLOPT_HEADER, 1L);
  43. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  44. easy_setopt(curl, CURLOPT_URL, URL);
  45. easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
  46. code = curl_easy_perform(curl);
  47. if(CURLE_OK != code) {
  48. fprintf(stderr, "%s:%d curl_easy_perform() failed, "
  49. "with code %d (%s)\n",
  50. __FILE__, __LINE__, code, curl_easy_strerror(code));
  51. res = TEST_ERR_MAJOR_BAD;
  52. goto test_cleanup;
  53. }
  54. code = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
  55. if(CURLE_OK != code) {
  56. fprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
  57. "with code %d (%s)\n",
  58. __FILE__, __LINE__, code, curl_easy_strerror(code));
  59. res = TEST_ERR_MAJOR_BAD;
  60. goto test_cleanup;
  61. }
  62. printf("header length is ........: %ld\n", headerSize);
  63. printf("header length should be..: %lu\n", realHeaderSize);
  64. test_cleanup:
  65. curl_easy_cleanup(curl);
  66. curl_global_cleanup();
  67. return res;
  68. }
  69. size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream)
  70. {
  71. fwrite(ptr, size, nmemb, stream);
  72. return nmemb * size;
  73. }
  74. size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream)
  75. {
  76. (void)ptr;
  77. (void)stream;
  78. realHeaderSize += curlx_uztoul(size * nmemb);
  79. return nmemb * size;
  80. }