Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1522.c
2649 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 "first.h"
25
26
/* test case and code based on https://github.com/curl/curl/issues/2847 */
27
28
#include "testtrace.h"
29
#include "memdebug.h"
30
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
48
static CURLcode test_lib1522(const char *URL)
49
{
50
static char g_Data[40 * 1024]; /* POST 40KB */
51
52
CURLcode code = TEST_ERR_MAJOR_BAD;
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
debug_config.nohex = TRUE;
64
debug_config.tracetime = TRUE;
65
test_setopt(curl, CURLOPT_DEBUGDATA, &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
curl_mprintf("uploadSize = %" CURL_FORMAT_CURL_OFF_T "\n", uploadSize);
81
82
if((size_t) uploadSize == sizeof(g_Data)) {
83
curl_mprintf("!!!!!!!!!! PASS\n");
84
}
85
else {
86
curl_mprintf("sent %zu, libcurl says %" CURL_FORMAT_CURL_OFF_T "\n",
87
sizeof(g_Data), uploadSize);
88
}
89
}
90
else {
91
curl_mprintf("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 code;
99
}
100
101