xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame^] | 1 | /*************************************************************************** |
| 2 | * _ _ ____ _ |
| 3 | * Project ___| | | | _ \| | |
| 4 | * / __| | | | |_) | | |
| 5 | * | (__| |_| | _ <| |___ |
| 6 | * \___|\___/|_| \_\_____| |
| 7 | * |
| 8 | * Copyright (C) 1998 - 2022, 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 |
| 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 | |
| 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 | } |
| 52 | int test(char *URL) |
| 53 | { |
| 54 | CURL *easy; |
| 55 | |
| 56 | curl_global_init(CURL_GLOBAL_DEFAULT); |
| 57 | |
| 58 | easy = curl_easy_init(); |
| 59 | if(easy) { |
| 60 | CURLcode res; |
| 61 | curl_easy_setopt(easy, CURLOPT_URL, URL); |
| 62 | curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L); |
| 63 | curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); |
| 64 | /* ignores any content */ |
| 65 | curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, write_cb); |
| 66 | |
| 67 | /* if there's a proxy set, use it */ |
| 68 | if(libtest_arg2 && *libtest_arg2) { |
| 69 | curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); |
| 70 | curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); |
| 71 | } |
| 72 | res = curl_easy_perform(easy); |
| 73 | if(res) { |
| 74 | printf("badness: %d\n", (int)res); |
| 75 | } |
| 76 | showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX); |
| 77 | curl_easy_cleanup(easy); |
| 78 | } |
| 79 | curl_global_cleanup(); |
| 80 | return 0; |
| 81 | } |