1 /***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24
25 #include "test.h"
26
27 #include "memdebug.h"
28
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 #pragma warning(disable:4706) /* assignment within conditional expression */
32 #endif
showem(CURL * easy,unsigned int type)33 static void showem(CURL *easy, unsigned int type)
34 {
35 struct curl_header *header = NULL;
36 struct curl_header *prev = NULL;
37
38 while((header = curl_easy_nextheader(easy, type, 0, prev))) {
39 printf(" %s == %s (%u/%u)\n", header->name, header->value,
40 (int)header->index, (int)header->amount);
41 prev = header;
42 }
43 }
44 #ifdef _MSC_VER
45 #pragma warning(pop)
46 #endif
47
write_cb(char * data,size_t n,size_t l,void * userp)48 static size_t write_cb(char *data, size_t n, size_t l, void *userp)
49 {
50 /* take care of the data here, ignored in this example */
51 (void)data;
52 (void)userp;
53 return n*l;
54 }
test(char * URL)55 CURLcode test(char *URL)
56 {
57 CURL *easy;
58 CURLcode res = CURLE_OK;
59
60 global_init(CURL_GLOBAL_DEFAULT);
61
62 easy_init(easy);
63 curl_easy_setopt(easy, CURLOPT_URL, URL);
64 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
65 curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
66 /* ignores any content */
67 curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
68
69 /* if there's a proxy set, use it */
70 if(libtest_arg2 && *libtest_arg2) {
71 curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
72 curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
73 }
74 res = curl_easy_perform(easy);
75 if(res) {
76 printf("badness: %d\n", res);
77 }
78 showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
79
80 test_cleanup:
81 curl_easy_cleanup(easy);
82 curl_global_cleanup();
83 return res;
84 }
85