lib1509.c 2.9 KB

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