lib553.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2011, 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 http://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. /* This test case and code is based on the bug recipe Joe Malicki provided for
  23. * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
  24. */
  25. #include "test.h"
  26. #include "memdebug.h"
  27. #define POSTLEN 40960
  28. static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
  29. {
  30. static size_t total=POSTLEN;
  31. static char buf[1024];
  32. (void)stream;
  33. memset(buf, 'A', sizeof(buf));
  34. size *= nmemb;
  35. if (size > total)
  36. size = total;
  37. if(size > sizeof(buf))
  38. size = sizeof(buf);
  39. memcpy(ptr, buf, size);
  40. total -= size;
  41. return size;
  42. }
  43. #define NUM_HEADERS 8
  44. #define SIZE_HEADERS 5000
  45. static char buf[SIZE_HEADERS + 100];
  46. int test(char *URL)
  47. {
  48. CURL *curl;
  49. CURLcode res = CURLE_FAILED_INIT;
  50. int i;
  51. struct curl_slist *headerlist=NULL, *hl;
  52. if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
  53. fprintf(stderr, "curl_global_init() failed\n");
  54. return TEST_ERR_MAJOR_BAD;
  55. }
  56. if((curl = curl_easy_init()) == NULL) {
  57. fprintf(stderr, "curl_easy_init() failed\n");
  58. curl_global_cleanup();
  59. return TEST_ERR_MAJOR_BAD;
  60. }
  61. for (i = 0; i < NUM_HEADERS; i++) {
  62. int len = sprintf(buf, "Header%d: ", i);
  63. memset(&buf[len], 'A', SIZE_HEADERS);
  64. buf[len + SIZE_HEADERS]=0; /* zero terminate */
  65. hl = curl_slist_append(headerlist, buf);
  66. if (!hl)
  67. goto test_cleanup;
  68. headerlist = hl;
  69. }
  70. hl = curl_slist_append(headerlist, "Expect: ");
  71. if (!hl)
  72. goto test_cleanup;
  73. headerlist = hl;
  74. test_setopt(curl, CURLOPT_URL, URL);
  75. test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
  76. test_setopt(curl, CURLOPT_POST, 1L);
  77. #ifdef CURL_DOES_CONVERSIONS
  78. /* Convert the POST data to ASCII */
  79. test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
  80. #endif
  81. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
  82. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  83. test_setopt(curl, CURLOPT_HEADER, 1L);
  84. test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
  85. res = curl_easy_perform(curl);
  86. test_cleanup:
  87. curl_easy_cleanup(curl);
  88. curl_slist_free_all(headerlist);
  89. curl_global_cleanup();
  90. return (int)res;
  91. }