Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1527.c
2066 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Vijay Panghal, <[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
25
/*
26
* This unit test PUT http data over proxy. Same http header will be generated
27
* for server and proxy
28
*/
29
30
#include "test.h"
31
32
#include "memdebug.h"
33
34
static char testdata[] = "Hello Cloud!\n";
35
36
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
37
{
38
size_t amount = nmemb * size; /* Total bytes curl wants */
39
if(amount < strlen(testdata)) {
40
return strlen(testdata);
41
}
42
(void)stream;
43
memcpy(ptr, testdata, strlen(testdata));
44
return strlen(testdata);
45
}
46
47
48
CURLcode test(char *URL)
49
{
50
CURL *curl = NULL;
51
CURLcode res = CURLE_FAILED_INIT;
52
/* http header list */
53
struct curl_slist *hhl = NULL, *tmp = NULL;
54
55
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
56
curl_mfprintf(stderr, "curl_global_init() failed\n");
57
return TEST_ERR_MAJOR_BAD;
58
}
59
60
curl = curl_easy_init();
61
if(!curl) {
62
curl_mfprintf(stderr, "curl_easy_init() failed\n");
63
curl_global_cleanup();
64
return TEST_ERR_MAJOR_BAD;
65
}
66
67
hhl = curl_slist_append(hhl, "User-Agent: Http Agent");
68
if(!hhl) {
69
goto test_cleanup;
70
}
71
tmp = curl_slist_append(hhl, "Expect: 100-continue");
72
if(!tmp) {
73
goto test_cleanup;
74
}
75
hhl = tmp;
76
77
test_setopt(curl, CURLOPT_URL, URL);
78
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
79
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
80
test_setopt(curl, CURLOPT_POST, 0L);
81
test_setopt(curl, CURLOPT_UPLOAD, 1L);
82
test_setopt(curl, CURLOPT_VERBOSE, 1L);
83
test_setopt(curl, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP);
84
test_setopt(curl, CURLOPT_HEADER, 1L);
85
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
86
test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
87
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
88
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(testdata));
89
test_setopt(curl, CURLOPT_HEADEROPT, (long)CURLHEADER_UNIFIED);
90
91
res = curl_easy_perform(curl);
92
93
test_cleanup:
94
95
curl_easy_cleanup(curl);
96
97
curl_slist_free_all(hhl);
98
99
curl_global_cleanup();
100
101
return res;
102
}
103
104