lib1977.c (2912B)
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 CURLcode test_lib1977(char *URL) 29 { 30 CURLcode res = CURLE_OK; 31 CURLU *curlu = curl_url(); 32 CURLU *curlu_2 = curl_url(); 33 CURL *curl; 34 char *effective = NULL; 35 36 global_init(CURL_GLOBAL_ALL); 37 easy_init(curl); 38 39 /* first transfer: set just the URL in the first CURLU handle */ 40 curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME); 41 easy_setopt(curl, CURLOPT_CURLU, curlu); 42 43 res = curl_easy_perform(curl); 44 if(res) 45 goto test_cleanup; 46 47 effective = NULL; 48 res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective); 49 if(res) 50 goto test_cleanup; 51 curl_mprintf("effective URL: %s\n", effective); 52 53 54 /* second transfer: set URL + query in the second CURLU handle */ 55 curl_url_set(curlu_2, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME); 56 curl_url_set(curlu_2, CURLUPART_QUERY, "foo", 0); 57 easy_setopt(curl, CURLOPT_CURLU, curlu_2); 58 59 res = curl_easy_perform(curl); 60 if(res) 61 goto test_cleanup; 62 63 effective = NULL; 64 res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective); 65 if(res) 66 goto test_cleanup; 67 curl_mprintf("effective URL: %s\n", effective); 68 69 70 /* third transfer: append extra query in the second CURLU handle, but do not 71 set CURLOPT_CURLU again. this is to test that the contents of the handle 72 is allowed to change between transfers and is used without having to set 73 CURLOPT_CURLU again */ 74 curl_url_set(curlu_2, CURLUPART_QUERY, "bar", CURLU_APPENDQUERY); 75 76 res = curl_easy_perform(curl); 77 if(res) 78 goto test_cleanup; 79 80 effective = NULL; 81 res = curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effective); 82 if(res) 83 goto test_cleanup; 84 curl_mprintf("effective URL: %s\n", effective); 85 86 87 test_cleanup: 88 curl_easy_cleanup(curl); 89 curl_url_cleanup(curlu); 90 curl_url_cleanup(curlu_2); 91 curl_global_cleanup(); 92 93 return res; 94 }