lib1556.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2021, 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. ***************************************************************************/
  22. #include "test.h"
  23. #include "testutil.h"
  24. #include "warnless.h"
  25. #include "memdebug.h"
  26. struct headerinfo {
  27. size_t largest;
  28. };
  29. static size_t header(void *ptr, size_t size, size_t nmemb, void *stream)
  30. {
  31. size_t headersize = size * nmemb;
  32. struct headerinfo *info = (struct headerinfo *)stream;
  33. (void)ptr;
  34. if(headersize > info->largest)
  35. /* remember the longest header */
  36. info->largest = headersize;
  37. return nmemb * size;
  38. }
  39. int test(char *URL)
  40. {
  41. CURLcode code;
  42. CURL *curl = NULL;
  43. int res = 0;
  44. struct headerinfo info = {0};
  45. global_init(CURL_GLOBAL_ALL);
  46. easy_init(curl);
  47. easy_setopt(curl, CURLOPT_HEADERFUNCTION, header);
  48. easy_setopt(curl, CURLOPT_HEADERDATA, &info);
  49. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  50. easy_setopt(curl, CURLOPT_URL, URL);
  51. code = curl_easy_perform(curl);
  52. if(CURLE_OK != code) {
  53. fprintf(stderr, "%s:%d curl_easy_perform() failed, "
  54. "with code %d (%s)\n",
  55. __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
  56. res = TEST_ERR_MAJOR_BAD;
  57. goto test_cleanup;
  58. }
  59. printf("Max = %ld\n", (long)info.largest);
  60. test_cleanup:
  61. curl_easy_cleanup(curl);
  62. curl_global_cleanup();
  63. return res;
  64. }