blob: 3e237e2d4f6c3c11bb885da1c6861fcd51569f2a [file] [log] [blame]
xf.li6c8fc1e2023-08-12 00:11:09 -07001/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 2019 - 2022, 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
30int test(char *URL)
31{
32 char *url_after;
33 CURLU *curlu = curl_url();
34 CURL *curl = curl_easy_init();
35 CURLcode curl_code;
36 char error_buffer[CURL_ERROR_SIZE] = "";
37
38 curl_url_set(curlu, CURLUPART_URL, URL, CURLU_DEFAULT_SCHEME);
39 curl_easy_setopt(curl, CURLOPT_CURLU, curlu);
40 curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
41 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
42 /* set a port number that makes this request fail */
43 curl_easy_setopt(curl, CURLOPT_PORT, 1L);
44 curl_code = curl_easy_perform(curl);
45 if(!curl_code)
46 fprintf(stderr, "failure expected, "
47 "curl_easy_perform returned %ld: <%s>, <%s>\n",
48 (long) curl_code, curl_easy_strerror(curl_code), error_buffer);
49
50 /* print the used url */
51 curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
52 fprintf(stderr, "curlu now: <%s>\n", url_after);
53 curl_free(url_after);
54
55 /* now reset CURLOP_PORT to go back to originally set port number */
56 curl_easy_setopt(curl, CURLOPT_PORT, 0L);
57
58 curl_code = curl_easy_perform(curl);
59 if(curl_code)
60 fprintf(stderr, "success expected, "
61 "curl_easy_perform returned %ld: <%s>, <%s>\n",
62 (long) curl_code, curl_easy_strerror(curl_code), error_buffer);
63
64 /* print url */
65 curl_url_get(curlu, CURLUPART_URL, &url_after, 0);
66 fprintf(stderr, "curlu now: <%s>\n", url_after);
67 curl_free(url_after);
68
69 curl_easy_cleanup(curl);
70 curl_url_cleanup(curlu);
71 curl_global_cleanup();
72
73 return 0;
74}