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