lib1947.c (2704B)
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 t1947_write_cb(char *data, size_t n, size_t l, void *userp) 29 { 30 /* ignore the data */ 31 (void)data; 32 (void)userp; 33 return n*l; 34 } 35 36 static CURLcode test_lib1947(char *URL) 37 { 38 CURL *curl; 39 CURLcode res = CURLE_OK; 40 struct curl_header *h; 41 int count = 0; 42 unsigned int origins; 43 44 global_init(CURL_GLOBAL_DEFAULT); 45 46 easy_init(curl); 47 48 /* perform a request that involves redirection */ 49 easy_setopt(curl, CURLOPT_URL, URL); 50 easy_setopt(curl, CURLOPT_WRITEFUNCTION, t1947_write_cb); 51 easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 52 res = curl_easy_perform(curl); 53 if(res) { 54 curl_mfprintf(stderr, "curl_easy_perform() failed: %s\n", 55 curl_easy_strerror(res)); 56 goto test_cleanup; 57 } 58 59 /* count the number of requests by reading the first header of each 60 request. */ 61 origins = (CURLH_HEADER|CURLH_TRAILER|CURLH_CONNECT| 62 CURLH_1XX|CURLH_PSEUDO); 63 do { 64 h = curl_easy_nextheader(curl, origins, count, NULL); 65 if(h) 66 count++; 67 } while(h); 68 curl_mprintf("count = %u\n", count); 69 70 /* perform another request - without redirect */ 71 easy_setopt(curl, CURLOPT_URL, libtest_arg2); 72 res = curl_easy_perform(curl); 73 if(res) { 74 curl_mfprintf(stderr, "curl_easy_perform() failed: %s\n", 75 curl_easy_strerror(res)); 76 goto test_cleanup; 77 } 78 79 /* count the number of requests again. */ 80 count = 0; 81 do { 82 h = curl_easy_nextheader(curl, origins, count, NULL); 83 if(h) 84 count++; 85 } while(h); 86 curl_mprintf("count = %u\n", count); 87 88 test_cleanup: 89 curl_easy_cleanup(curl); 90 curl_global_cleanup(); 91 return res; 92 }