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