lib1556.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. struct headerinfo {
  29. size_t largest;
  30. };
  31. static size_t header(void *ptr, size_t size, size_t nmemb, void *stream)
  32. {
  33. size_t headersize = size * nmemb;
  34. struct headerinfo *info = (struct headerinfo *)stream;
  35. (void)ptr;
  36. if(headersize > info->largest)
  37. /* remember the longest header */
  38. info->largest = headersize;
  39. return nmemb * size;
  40. }
  41. int test(char *URL)
  42. {
  43. CURLcode code;
  44. CURL *curl = NULL;
  45. int res = 0;
  46. struct headerinfo info = {0};
  47. global_init(CURL_GLOBAL_ALL);
  48. easy_init(curl);
  49. easy_setopt(curl, CURLOPT_HEADERFUNCTION, header);
  50. easy_setopt(curl, CURLOPT_HEADERDATA, &info);
  51. easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  52. easy_setopt(curl, CURLOPT_URL, URL);
  53. code = curl_easy_perform(curl);
  54. if(CURLE_OK != code) {
  55. fprintf(stderr, "%s:%d curl_easy_perform() failed, "
  56. "with code %d (%s)\n",
  57. __FILE__, __LINE__, (int)code, curl_easy_strerror(code));
  58. res = TEST_ERR_MAJOR_BAD;
  59. goto test_cleanup;
  60. }
  61. printf("Max = %ld\n", (long)info.largest);
  62. test_cleanup:
  63. curl_easy_cleanup(curl);
  64. curl_global_cleanup();
  65. return res;
  66. }