xref: /curl/tests/libtest/lib1945.c (revision 25cbc2f7)
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 /* warning C4706: assignment within conditional expression */
31 #pragma warning(disable:4706)
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 
write_cb(char * data,size_t n,size_t l,void * userp)45 static size_t write_cb(char *data, size_t n, size_t l, void *userp)
46 {
47   /* take care of the data here, ignored in this example */
48   (void)data;
49   (void)userp;
50   return n*l;
51 }
test(char * URL)52 CURLcode test(char *URL)
53 {
54   CURL *easy;
55   CURLcode res = CURLE_OK;
56 
57   global_init(CURL_GLOBAL_DEFAULT);
58 
59   easy_init(easy);
60   curl_easy_setopt(easy, CURLOPT_URL, URL);
61   curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
62   curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
63   /* ignores any content */
64   curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb);
65 
66   /* if there's a proxy set, use it */
67   if(libtest_arg2 && *libtest_arg2) {
68     curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2);
69     curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L);
70   }
71   res = curl_easy_perform(easy);
72   if(res) {
73     printf("badness: %d\n", res);
74   }
75   showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX);
76 
77 test_cleanup:
78   curl_easy_cleanup(easy);
79   curl_global_cleanup();
80   return res;
81 }
82