lib553.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2018, 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. /* 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. curl = curl_easy_init();
  57. if(!curl) {
  58. fprintf(stderr, "curl_easy_init() failed\n");
  59. curl_global_cleanup();
  60. return TEST_ERR_MAJOR_BAD;
  61. }
  62. for(i = 0; i < NUM_HEADERS; i++) {
  63. int len = msnprintf(buf, sizeof(buf), "Header%d: ", i);
  64. memset(&buf[len], 'A', SIZE_HEADERS);
  65. buf[len + SIZE_HEADERS] = 0; /* zero terminate */
  66. hl = curl_slist_append(headerlist, buf);
  67. if(!hl)
  68. goto test_cleanup;
  69. headerlist = hl;
  70. }
  71. hl = curl_slist_append(headerlist, "Expect: ");
  72. if(!hl)
  73. goto test_cleanup;
  74. headerlist = hl;
  75. test_setopt(curl, CURLOPT_URL, URL);
  76. test_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
  77. test_setopt(curl, CURLOPT_POST, 1L);
  78. #ifdef CURL_DOES_CONVERSIONS
  79. /* Convert the POST data to ASCII */
  80. test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
  81. #endif
  82. test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
  83. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  84. test_setopt(curl, CURLOPT_HEADER, 1L);
  85. test_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
  86. res = curl_easy_perform(curl);
  87. test_cleanup:
  88. curl_easy_cleanup(curl);
  89. curl_slist_free_all(headerlist);
  90. curl_global_cleanup();
  91. return (int)res;
  92. }