lib1945.c (2486B)
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.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 #include "first.h" 25 26 #include "memdebug.h" 27 28 static void t1945_showem(CURL *easy, unsigned int type) 29 { 30 struct curl_header *header = NULL; 31 struct curl_header *prev = NULL; 32 33 /* !checksrc! disable EQUALSNULL 1 */ 34 while((header = curl_easy_nextheader(easy, type, 0, prev)) != NULL) { 35 curl_mprintf(" %s == %s (%u/%u)\n", header->name, header->value, 36 (int)header->index, (int)header->amount); 37 prev = header; 38 } 39 } 40 41 static size_t t1945_write_cb(char *data, size_t n, size_t l, void *userp) 42 { 43 /* take care of the data here, ignored in this example */ 44 (void)data; 45 (void)userp; 46 return n*l; 47 } 48 49 static CURLcode test_lib1945(char *URL) 50 { 51 CURL *easy; 52 CURLcode res = CURLE_OK; 53 54 global_init(CURL_GLOBAL_DEFAULT); 55 56 easy_init(easy); 57 curl_easy_setopt(easy, CURLOPT_URL, URL); 58 curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L); 59 curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); 60 /* ignores any content */ 61 curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, t1945_write_cb); 62 63 /* if there's a proxy set, use it */ 64 if(libtest_arg2 && *libtest_arg2) { 65 curl_easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); 66 curl_easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); 67 } 68 res = curl_easy_perform(easy); 69 if(res) { 70 curl_mprintf("badness: %d\n", res); 71 } 72 t1945_showem(easy, CURLH_CONNECT|CURLH_HEADER|CURLH_TRAILER|CURLH_1XX); 73 74 test_cleanup: 75 curl_easy_cleanup(easy); 76 curl_global_cleanup(); 77 return res; 78 }