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