master
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 "unitcheck.h"
25#include "urldata.h"
26#include "vtls/vtls.h"
28#ifdef HAVE_NET_IF_H
29#include <net/if.h>
30#endif
32#if defined(HAVE_IF_NAMETOINDEX) && defined(USE_WINSOCK)
33#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 5)
34#include <wincrypt.h> /* workaround for old mingw-w64 missing to include it */
35#endif
36#include <iphlpapi.h>
37#endif
39static CURLcode test_create2413(const char *name,
40 CURL *curl,
41 const struct Curl_scheme *scheme,
42 const char *hostname,
43 uint16_t port,
44 const char *exp_hostname,
45 bool exp_ipv6,
46 const char *exp_zoneid,
47 int exp_scopeid)
48{
49 struct Curl_peer *peer = NULL;
50 CURLcode result;
52 result = Curl_peer_create((struct Curl_easy *)curl,
53 scheme, hostname, port, &peer);
54 if(result) {
55 curl_mfprintf(stderr, "%s: create failed %d", name, (int)result);
56 goto out;
57 }
59 result = CURLE_FAILED_INIT;
60#ifndef USE_IPV6
61 (void)exp_scopeid;
62#endif
64 if(peer->scheme != scheme) {
65 curl_mfprintf(stderr, "%s: has wrong scheme", name);
66 }
67 else if(!curl_strequal(peer->user_hostname, hostname)) {
68 curl_mfprintf(stderr, "%s: user_hostname=%s, expected %s", name,
69 peer->user_hostname, exp_hostname);
70 }
71 else if(exp_hostname && !curl_strequal(peer->hostname, exp_hostname))
72 curl_mfprintf(stderr, "%s: hostname=%s, expected %s", name,
73 peer->hostname, exp_hostname);
74 else if(peer->port != port)
75 curl_mfprintf(stderr, "%s: port=%u, expected %u", name,
76 peer->port, port);
77 else if((bool)peer->ipv6 != exp_ipv6)
78 curl_mfprintf(stderr, "%s: ipv6=%d, expected %d", name,
79 peer->ipv6, exp_ipv6);
80 else if(exp_zoneid &&
81 (!peer->zoneid || !curl_strequal(exp_zoneid, peer->zoneid)))
82 curl_mfprintf(stderr, "%s: zoneid=%s, expected %s", name,
83 peer->zoneid, exp_zoneid);
84 else if(!exp_zoneid && peer->zoneid)
85 curl_mfprintf(stderr, "%s: zoneid=%s, expected nothing", name,
86 peer->zoneid);
87#ifdef USE_IPV6
88 else if((exp_scopeid >= 0) && (peer->scopeid != (uint32_t)exp_scopeid))
89 curl_mfprintf(stderr, "%s: scopeid=%u, expected %d", name,
90 peer->scopeid, exp_scopeid);
91#endif
92 else
93 result = CURLE_OK;
95out:
96 Curl_peer_unlink(&peer);
97 fail_unless(!result, "check failed");
98 return result;
99}
101static CURLcode t2413_cmp(const char *name,
102 CURL *curl,
103 const struct Curl_scheme *scheme1,
104 const char *hostname1,
105 uint16_t port1,
106 const struct Curl_scheme *scheme2,
107 const char *hostname2,
108 uint16_t port2,
109 bool exp_equal,
110 bool exp_same_dest)
111{
112 struct Curl_peer *peer1 = NULL;
113 struct Curl_peer *peer2 = NULL;
114 CURLcode result;
116 result = Curl_peer_create((struct Curl_easy *)curl,
117 scheme1, hostname1, port1, &peer1);
118 if(result) {
119 curl_mfprintf(stderr, "%s: create peer1 failed %d", name, (int)result);
120 goto out;
121 }
122 result = Curl_peer_create((struct Curl_easy *)curl,
123 scheme2, hostname2, port2, &peer2);
124 if(result) {
125 curl_mfprintf(stderr, "%s: create peer2 failed %d", name, (int)result);
126 goto out;
127 }
129 result = CURLE_FAILED_INIT;
130 if(exp_equal != Curl_peer_equal(peer1, peer2))
131 curl_mfprintf(stderr, "%s: equal check failed, not %s", name,
132 exp_equal ? "equal" : "different");
133 else if(exp_same_dest != Curl_peer_same_destination(peer1, peer2))
134 curl_mfprintf(stderr, "%s: same destination, not %s", name,
135 exp_equal ? "the same" : "different");
136 else
137 result = CURLE_OK;
139out:
140 Curl_peer_unlink(&peer1);
141 Curl_peer_unlink(&peer2);
142 fail_unless(!result, "check failed");
143 return result;
144}
146#ifndef CURL_DISABLE_PROXY
147static CURLcode t2413_proxy(const char *name,
148 CURL *curl,
149 const char *proxy,
150 uint8_t proxytype,
151 long proxyport,
152 uint16_t exp_port)
153{
154 struct Curl_peer *peer = NULL;
155 uint8_t ptype = proxytype;
156 CURLU *uh = curl_url();
157 CURLcode result = CURLE_OUT_OF_MEMORY;
159 if(!uh)
160 goto out;
161 /* parse it the same way the proxy setup does */
162 if(curl_url_set(uh, CURLUPART_URL, proxy,
163 CURLU_NON_SUPPORT_SCHEME | CURLU_GUESS_SCHEME)) {
164 curl_mfprintf(stderr, "%s: failed to parse %s", name, proxy);
165 result = CURLE_URL_MALFORMAT;
166 goto out;
167 }
168 curl_easy_setopt(curl, CURLOPT_PROXYPORT, proxyport);
170 result = Curl_peer_from_proxy_url(uh, (struct Curl_easy *)curl, proxy,
171 proxytype, &peer, &ptype);
172 if(result) {
173 curl_mfprintf(stderr, "%s: create failed %d", name, (int)result);
174 goto out;
175 }
176 if(peer->port != exp_port) {
177 curl_mfprintf(stderr, "%s: port=%u, expected %u", name,
178 peer->port, exp_port);
179 result = CURLE_FAILED_INIT;
180 }
182out:
183 Curl_peer_unlink(&peer);
184 curl_url_cleanup(uh);
185 fail_unless(!result, "check failed");
186 return result;
187}
188#endif
190static uint32_t t2413_scopeid(const char *zone)
191{
192#ifdef HAVE_IF_NAMETOINDEX
193 return (uint32_t)if_nametoindex(zone);
194#else
195 (void)zone;
196 return 0;
197#endif
198}
200static CURLcode test_unit2413(const char *arg)
201{
202 UNITTEST_BEGIN_SIMPLE
203 CURL *curl;
205 curl_global_init(CURL_GLOBAL_ALL);
206 curl = curl_easy_init();
207 if(!curl) {
208 curl_global_cleanup();
209 goto unit_test_abort;
210 }
212 test_create2413("peer1", curl, &Curl_scheme_https, "test.curl.se", 1234,
213 "test.curl.se", FALSE, NULL, 0);
214 test_create2413("peer2", curl, &Curl_scheme_https, "127.0.0.1", 1234,
215 "127.0.0.1", FALSE, NULL, 0);
216 test_create2413("peer3", curl, &Curl_scheme_https, "::1", 1234,
217 "::1", TRUE, NULL, 0);
218 test_create2413("peer4", curl, &Curl_scheme_https, "[::1]", 1234,
219 "::1", TRUE, NULL, 0);
220 test_create2413("peer5", curl, &Curl_scheme_https, "test.curl.se.", 1234,
221 "test.curl.se.", FALSE, NULL, 0);
222 test_create2413("peer6", curl, &Curl_scheme_https, "[::1%tada]", 1234,
223 "::1", TRUE, "tada", t2413_scopeid("tada"));
224 test_create2413("peer7", curl, &Curl_scheme_https, "::1%tada", 1234,
225 "::1", TRUE, "tada", t2413_scopeid("tada"));
226 test_create2413("peer8", curl, &Curl_scheme_https, "::1%123", 1234,
227 "::1", TRUE, "123", 123);
228 test_create2413("peer9", curl, &Curl_scheme_https, "::1%123x", 1234,
229 "::1", TRUE, "123x", t2413_scopeid("123x"));
231 t2413_cmp("cmp1", curl,
232 &Curl_scheme_https, "test.curl.se", 1234,
233 &Curl_scheme_https, "test.curl.se", 1234, TRUE, TRUE);
234 t2413_cmp("cmp2", curl,
235 &Curl_scheme_https, "Test.curl.se", 1234,
236 &Curl_scheme_https, "test.curl.se", 1234, TRUE, TRUE);
237 t2413_cmp("cmp3", curl,
238 &Curl_scheme_http, "test.curl.se", 1234,
239 &Curl_scheme_https, "test.curl.se", 1234, FALSE, TRUE);
240 t2413_cmp("cmp4", curl,
241 &Curl_scheme_https, "test.curl.se", 1234,
242 &Curl_scheme_https, "test.curl.se", 443, FALSE, FALSE);
243 t2413_cmp("cmp5", curl,
244 &Curl_scheme_https, "[::1%tada]", 443,
245 &Curl_scheme_https, "[::1%tada]", 443, TRUE, TRUE);
246 t2413_cmp("cmp6", curl,
247 &Curl_scheme_https, "[::1%tada]", 443,
248 &Curl_scheme_https, "[::1%Tada]", 443, FALSE, FALSE);
250#ifndef CURL_DISABLE_PROXY
251 /* an explicit port is used, even when it is the default for the
252 (possibly guessed) scheme */
253 t2413_proxy("proxy1", curl, "127.0.0.1:80", CURLPROXY_SOCKS5, 0, 80);
254 t2413_proxy("proxy2", curl, "127.0.0.1:443", CURLPROXY_SOCKS4, 0, 443);
255 t2413_proxy("proxy3", curl, "socks5h://127.0.0.1:80", CURLPROXY_HTTP, 0,
256 80);
257 /* an explicit port overrides CURLOPT_PROXYPORT */
258 t2413_proxy("proxy4", curl, "http://127.0.0.1:80", CURLPROXY_HTTP, 3128,
259 80);
260 t2413_proxy("proxy5", curl, "socks5://127.0.0.1:1080", CURLPROXY_HTTP,
261 9999, 1080);
262 /* without a port, use CURLOPT_PROXYPORT or the default */
263 t2413_proxy("proxy6", curl, "127.0.0.1", CURLPROXY_HTTP, 3128, 3128);
264 t2413_proxy("proxy7", curl, "127.0.0.1", CURLPROXY_HTTP, 0, 1080);
265 t2413_proxy("proxy8", curl, "http://127.0.0.1", CURLPROXY_HTTP, 0, 1080);
266 t2413_proxy("proxy9", curl, "socks4://127.0.0.1", CURLPROXY_HTTP, 0, 1080);
267 if(Curl_ssl_supports((struct Curl_easy *)curl, SSLSUPP_HTTPS_PROXY)) {
268 t2413_proxy("proxy10", curl, "https://127.0.0.1", CURLPROXY_HTTP, 0,
269 443);
270 t2413_proxy("proxy11", curl, "https://127.0.0.1:443", CURLPROXY_HTTP,
271 3129, 443);
272 }
273 curl_easy_setopt(curl, CURLOPT_PROXYPORT, 0L);
274#endif
276 curl_easy_cleanup(curl);
277 curl_global_cleanup();
279 UNITTEST_END_SIMPLE
280}
Diagnostics4 git calls · 25 ms
CallStatusSizeTime025 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.5 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=2539 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=fba6aa612d6695a09b525bc781003556a8205a9d git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2539 git.pkt.payload.max=2518 git.sideband.band1.bytes=2517 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2e930ee25ecfa
- Request
- 56716ee3…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format