Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1518.c
2651 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 "first.h"
25
26
#include "memdebug.h"
27
28
/* Test inspired by github issue 3340 */
29
30
static size_t t1518_write_cb(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
static CURLcode test_lib1518(const 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
CURLU *urlu = NULL;
49
curl = curl_easy_init();
50
if(!curl) {
51
curl_mfprintf(stderr, "curl_easy_init() failed\n");
52
curl_global_cleanup();
53
return TEST_ERR_MAJOR_BAD;
54
}
55
if(testnum == 1543) {
56
/* set CURLOPT_URLU */
57
CURLUcode rc = CURLUE_OK;
58
urlu = curl_url();
59
if(urlu)
60
rc = curl_url_set(urlu, CURLUPART_URL, URL, CURLU_ALLOW_SPACE);
61
if(!urlu || rc) {
62
goto test_cleanup;
63
}
64
test_setopt(curl, CURLOPT_CURLU, urlu);
65
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
66
}
67
else {
68
test_setopt(curl, CURLOPT_URL, URL);
69
/* just to make it explicit and visible in this test: */
70
test_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L);
71
}
72
73
/* Perform the request, res will get the return code */
74
res = curl_easy_perform(curl);
75
if(res)
76
goto test_cleanup;
77
78
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode);
79
curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount);
80
curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &effectiveUrl);
81
curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &redirectUrl);
82
test_setopt(curl, CURLOPT_WRITEFUNCTION, t1518_write_cb);
83
84
curl_mprintf("res %d\n"
85
"status %ld\n"
86
"redirects %ld\n"
87
"effectiveurl %s\n"
88
"redirecturl %s\n",
89
res,
90
curlResponseCode,
91
curlRedirectCount,
92
effectiveUrl,
93
redirectUrl ? redirectUrl : "blank");
94
95
test_cleanup:
96
97
/* always cleanup */
98
curl_easy_cleanup(curl);
99
curl_global_cleanup();
100
curl_url_cleanup(urlu);
101
return res;
102
}
103
104