lib1940.c (3520B)
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 size_t t1940_write_cb(char *data, size_t n, size_t l, void *userp) 29 { 30 /* take care of the data here, ignored in this example */ 31 (void)data; 32 (void)userp; 33 return n*l; 34 } 35 36 static void t1940_showem(CURL *easy, int header_request, unsigned int type) 37 { 38 static const char *testdata[] = { 39 "daTE", 40 "Server", 41 "content-type", 42 "content-length", 43 "location", 44 "set-cookie", 45 "silly-thing", 46 "fold", 47 "blank", 48 "Blank2", 49 NULL 50 }; 51 52 int i; 53 struct curl_header *header; 54 for(i = 0; testdata[i]; i++) { 55 if(CURLHE_OK == curl_easy_header(easy, testdata[i], 0, 56 type, header_request, &header)) { 57 if(header->amount > 1) { 58 /* more than one, iterate over them */ 59 size_t index = 0; 60 size_t amount = header->amount; 61 do { 62 curl_mprintf("- %s == %s (%u/%u)\n", header->name, header->value, 63 (int)index, (int)amount); 64 65 if(++index == amount) 66 break; 67 if(CURLHE_OK != curl_easy_header(easy, testdata[i], index, 68 type, header_request, &header)) 69 break; 70 } while(1); 71 } 72 else { 73 /* only one of this */ 74 curl_mprintf(" %s == %s\n", header->name, header->value); 75 } 76 } 77 } 78 } 79 80 static CURLcode test_lib1940(char *URL) 81 { 82 CURL *easy = NULL; 83 CURLcode res = CURLE_OK; 84 85 int header_request; 86 if(testnum == 1946) { 87 header_request = 0; 88 } 89 else { 90 header_request = -1; 91 } 92 93 global_init(CURL_GLOBAL_DEFAULT); 94 easy_init(easy); 95 easy_setopt(easy, CURLOPT_URL, URL); 96 easy_setopt(easy, CURLOPT_VERBOSE, 1L); 97 easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L); 98 /* ignores any content */ 99 easy_setopt(easy, CURLOPT_WRITEFUNCTION, t1940_write_cb); 100 101 /* if there's a proxy set, use it */ 102 if(libtest_arg2 && *libtest_arg2) { 103 easy_setopt(easy, CURLOPT_PROXY, libtest_arg2); 104 easy_setopt(easy, CURLOPT_HTTPPROXYTUNNEL, 1L); 105 } 106 res = curl_easy_perform(easy); 107 if(res) 108 goto test_cleanup; 109 110 t1940_showem(easy, header_request, CURLH_HEADER); 111 if(libtest_arg2 && *libtest_arg2) { 112 /* now show connect headers only */ 113 t1940_showem(easy, header_request, CURLH_CONNECT); 114 } 115 t1940_showem(easy, header_request, CURLH_1XX); 116 t1940_showem(easy, header_request, CURLH_TRAILER); 117 118 test_cleanup: 119 curl_easy_cleanup(easy); 120 curl_global_cleanup(); 121 return res; 122 }