lib1522.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. /* test case and code based on https://github.com/curl/curl/issues/2847 */
  26. #include "testtrace.h"
  27. #include "testutil.h"
  28. #include "warnless.h"
  29. #include "memdebug.h"
  30. static char g_Data[40 * 1024]; /* POST 40KB */
  31. static int sockopt_callback(void *clientp, curl_socket_t curlfd,
  32. curlsocktype purpose)
  33. {
  34. #if defined(SOL_SOCKET) && defined(SO_SNDBUF)
  35. int sndbufsize = 4 * 1024; /* 4KB send buffer */
  36. (void) clientp;
  37. (void) purpose;
  38. setsockopt(curlfd, SOL_SOCKET, SO_SNDBUF,
  39. (char *)&sndbufsize, sizeof(sndbufsize));
  40. #else
  41. (void)clientp;
  42. (void)curlfd;
  43. (void)purpose;
  44. #endif
  45. return CURL_SOCKOPT_OK;
  46. }
  47. CURLcode test(char *URL)
  48. {
  49. CURLcode code = TEST_ERR_MAJOR_BAD;
  50. CURLcode res;
  51. struct curl_slist *pHeaderList = NULL;
  52. CURL *curl = curl_easy_init();
  53. memset(g_Data, 'A', sizeof(g_Data)); /* send As! */
  54. curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
  55. curl_easy_setopt(curl, CURLOPT_URL, URL);
  56. curl_easy_setopt(curl, CURLOPT_POSTFIELDS, g_Data);
  57. curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)sizeof(g_Data));
  58. libtest_debug_config.nohex = 1;
  59. libtest_debug_config.tracetime = 1;
  60. test_setopt(curl, CURLOPT_DEBUGDATA, &libtest_debug_config);
  61. test_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
  62. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  63. /* Remove "Expect: 100-continue" */
  64. pHeaderList = curl_slist_append(pHeaderList, "Expect:");
  65. curl_easy_setopt(curl, CURLOPT_HTTPHEADER, pHeaderList);
  66. code = curl_easy_perform(curl);
  67. if(code == CURLE_OK) {
  68. curl_off_t uploadSize;
  69. curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD_T, &uploadSize);
  70. printf("uploadSize = %ld\n", (long)uploadSize);
  71. if((size_t) uploadSize == sizeof(g_Data)) {
  72. printf("!!!!!!!!!! PASS\n");
  73. }
  74. else {
  75. printf("sent %d, libcurl says %d\n",
  76. (int)sizeof(g_Data), (int)uploadSize);
  77. }
  78. }
  79. else {
  80. printf("curl_easy_perform() failed. e = %d\n", code);
  81. }
  82. test_cleanup:
  83. curl_slist_free_all(pHeaderList);
  84. curl_easy_cleanup(curl);
  85. curl_global_cleanup();
  86. return code;
  87. }