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