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