Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1525.c
2653 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Daniel Stenberg, <[email protected]>, et al.
9
* Copyright (C) Vijay Panghal, <[email protected]>, et al.
10
*
11
* This software is licensed as described in the file COPYING, which
12
* you should have received as part of this distribution. The terms
13
* are also available at https://curl.se/docs/copyright.html.
14
*
15
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
16
* copies of the Software, and permit persons to whom the Software is
17
* furnished to do so, under the terms of the COPYING file.
18
*
19
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20
* KIND, either express or implied.
21
*
22
* SPDX-License-Identifier: curl
23
*
24
***************************************************************************/
25
26
/*
27
* This unit test PUT http data over proxy. Proxy header will be different
28
* from server http header
29
*/
30
31
#include "first.h"
32
33
#include "memdebug.h"
34
35
static const char t1525_testdata[] = "Hello Cloud!\n";
36
37
static size_t t1525_read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
38
{
39
size_t amount = nmemb * size; /* Total bytes curl wants */
40
if(amount < strlen(t1525_testdata)) {
41
return strlen(t1525_testdata);
42
}
43
(void)stream;
44
memcpy(ptr, t1525_testdata, strlen(t1525_testdata));
45
return strlen(t1525_testdata);
46
}
47
48
static CURLcode test_lib1525(const char *URL)
49
{
50
CURL *curl = NULL;
51
CURLcode res = CURLE_FAILED_INIT;
52
/* http and proxy header list */
53
struct curl_slist *hhl = 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
69
if(!hhl) {
70
goto test_cleanup;
71
}
72
73
test_setopt(curl, CURLOPT_URL, URL);
74
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
75
test_setopt(curl, CURLOPT_HTTPHEADER, hhl);
76
test_setopt(curl, CURLOPT_PROXYHEADER, hhl);
77
test_setopt(curl, CURLOPT_HEADEROPT, CURLHEADER_UNIFIED);
78
test_setopt(curl, CURLOPT_POST, 0L);
79
test_setopt(curl, CURLOPT_UPLOAD, 1L);
80
test_setopt(curl, CURLOPT_VERBOSE, 1L);
81
test_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
82
test_setopt(curl, CURLOPT_HEADER, 1L);
83
test_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
84
test_setopt(curl, CURLOPT_READFUNCTION, t1525_read_cb);
85
test_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
86
test_setopt(curl, CURLOPT_INFILESIZE, (long)strlen(t1525_testdata));
87
88
res = curl_easy_perform(curl);
89
90
test_cleanup:
91
92
curl_easy_cleanup(curl);
93
94
curl_slist_free_all(hhl);
95
96
curl_global_cleanup();
97
98
return res;
99
}
100
101