Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1518.c
2066 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) 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.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 "memdebug.h"
27
28
/* Test inspired by github issue 3340 */
29
30
static size_t writecb(char *buffer, size_t size, size_t nitems,
31
void *outstream)
32
{
33
(void)buffer;
34
(void)size;
35
(void)nitems;
36
(void)outstream;
37
return 0;
38
}
39
40
CURLcode test(char *URL)
41
{
42
CURL *curl;
43
CURLcode res = CURLE_OK;
44
long curlResponseCode;
45
long curlRedirectCount;
46
char *effectiveUrl = NULL;
47
char *redirectUrl = NULL;
48
#ifdef LIB1543
49
CURLU *urlu = NULL;
50
#endif
51
curl = curl_easy_init();
52
if(!curl) {
53
curl_mfprintf(stderr, "curl_easy_init() failed\n");
54
curl_global_cleanup();
55
return TEST_ERR_MAJOR_BAD;
56
}
57
#ifdef LIB1543
58
/* set CURLOPT_URLU */
59
{
60
CURLUcode rc = CURLUE_OK;
61
urlu = curl_url();
62
if(urlu)
63
rc = curl_url_set(urlu, CURLUPART_URL, URL, CURLU_ALLOW_SPACE);
64
if(!urlu || rc) {
65
goto test_cleanup;
66
}
67
test_setopt(curl, CURLOPT_CURLU, urlu);
68
}
69
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
70
#else
71
test_setopt(curl, CURLOPT_URL, URL);
72
/* just to make it explicit and visible in this test: */
73
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
74
#endif
75
76
77
/* Perform the request, res will get the return code */
78
res = curl_easy_perform(curl);
79
if(res)
80
goto test_cleanup;
81
82
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode);
83
curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
84
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
85
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
86
test_setopt(curl, CURLOPT_WRITEFUNCTION, writecb);
87
88
curl_mprintf("res %d\n"
89
"status %ld\n"
90
"redirects %ld\n"
91
"effectiveurl %s\n"
92
"redirecturl %s\n",
93
res,
94
curlResponseCode,
95
curlRedirectCount,
96
effectiveUrl,
97
redirectUrl ? redirectUrl : "blank");
98
99
test_cleanup:
100
101
/* always cleanup */
102
curl_easy_cleanup(curl);
103
curl_global_cleanup();
104
#ifdef LIB1543
105
curl_url_cleanup(urlu);
106
#endif
107
return res;
108
}
109
110