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