lib553.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*****************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * $Id$
  9. *
  10. * This test case and code is based on the bug recipe Joe Malicki provided for
  11. * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
  12. */
  13. #include "test.h"
  14. #define POSTLEN 40960
  15. static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
  16. {
  17. static size_t total=POSTLEN;
  18. static char buf[1024];
  19. (void)stream;
  20. memset(buf, 'A', sizeof(buf));
  21. size *= nmemb;
  22. if (size > total)
  23. size = total;
  24. if(size > sizeof(buf))
  25. size = sizeof(buf);
  26. memcpy(ptr, buf, size);
  27. total -= size;
  28. return size;
  29. }
  30. #define NUM_HEADERS 8
  31. #define SIZE_HEADERS 5000
  32. static char buf[SIZE_HEADERS + 100];
  33. int test(char *URL)
  34. {
  35. CURL *curl;
  36. CURLcode res;
  37. int i;
  38. struct curl_slist *headerlist=NULL, *hl;
  39. curl_global_init(CURL_GLOBAL_ALL);
  40. curl = curl_easy_init();
  41. if(curl) {
  42. for (i = 0; i < NUM_HEADERS; i++) {
  43. int len = sprintf(buf, "Header%d: ", i);
  44. memset(&buf[len], 'A', SIZE_HEADERS);
  45. buf[len + SIZE_HEADERS]=0; /* zero terminate */
  46. hl = curl_slist_append(headerlist, buf);
  47. if (!hl)
  48. goto errout;
  49. headerlist = hl;
  50. }
  51. hl = curl_slist_append(headerlist, "Expect: ");
  52. if (!hl)
  53. goto errout;
  54. headerlist = hl;
  55. curl_easy_setopt(curl, CURLOPT_URL, URL);
  56. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
  57. curl_easy_setopt(curl, CURLOPT_POST, 1L);
  58. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
  59. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  60. curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
  61. curl_easy_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
  62. res = curl_easy_perform(curl);
  63. errout:
  64. curl_easy_cleanup(curl);
  65. curl_slist_free_all(headerlist);
  66. }
  67. curl_global_cleanup();
  68. return (int)res;
  69. }