Artifactspublic-v0

curl

master
ply4 git calls234 ms311 KiB2 cachedprotocol v2
2561 lines80 KiBRaw
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 "curl_setup.h"
26#ifdef HAVE_NETINET_IN_H
27#include <netinet/in.h>
28#endif
29#ifdef HAVE_NETDB_H
30#include <netdb.h>
31#endif
32#ifdef HAVE_ARPA_INET_H
33#include <arpa/inet.h>
34#endif
35#ifdef HAVE_NET_IF_H
36#include <net/if.h>
37#endif
38#ifdef HAVE_IPHLPAPI_H
39#include <Iphlpapi.h>
40#endif
41#ifdef HAVE_SYS_IOCTL_H
42#include <sys/ioctl.h>
43#endif
44#ifdef HAVE_SYS_PARAM_H
45#include <sys/param.h>
46#endif
48#ifdef __VMS
49#include <in.h>
50#include <inet.h>
51#endif
53#ifdef HAVE_SYS_UN_H
54#include <sys/un.h>
55#endif
57#ifndef HAVE_SOCKET
58#error "We cannot compile without socket() support"
59#endif
61#if defined(HAVE_IF_NAMETOINDEX) && defined(USE_WINSOCK)
62#if defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR <= 5)
63#include <wincrypt.h> /* workaround for old mingw-w64 missing to include it */
64#endif
65#include <iphlpapi.h>
66#endif
68#include "urldata.h"
69#include "mime.h"
70#include "bufref.h"
71#include "vtls/vtls.h"
72#include "vssh/vssh.h"
73#include "transfer.h"
74#include "curl_addrinfo.h"
75#include "curl_trc.h"
76#include "progress.h"
77#include "cookie.h"
78#include "strcase.h"
79#include "escape.h"
80#include "curl_share.h"
81#include "http_digest.h"
82#include "multiif.h"
83#include "getinfo.h"
84#include "pop3.h"
85#include "urlapi-int.h"
86#include "hsts.h"
87#include "proxy.h"
88#include "cfilters.h"
89#include "idn.h"
90#include "http_proxy.h"
91#include "conncache.h"
92#include "multihandle.h"
93#include "curlx/strdup.h"
94#include "setopt.h"
95#include "altsvc.h"
96#include "curlx/dynbuf.h"
97#include "headers.h"
98#include "curlx/strerr.h"
99#include "curlx/strparse.h"
100#include "peer.h"
102/* Now for the protocols */
103#include "ftp.h"
104#include "dict.h"
105#include "telnet.h"
106#include "tftp.h"
107#include "http.h"
108#include "vauth/vauth.h"
109#include "file.h"
110#include "curl_ldap.h"
111#include "vssh/ssh.h"
112#include "imap.h"
113#include "url.h"
114#include "connect.h"
115#include "gopher.h"
116#include "mqtt.h"
117#include "rtsp.h"
118#include "smtp.h"
119#include "ws.h"
121/* Some parts of the code (e.g. chunked encoding) assume this buffer has more
122 * than a few bytes to play with. Do not let it become too small or bad things
123 * will happen.
124 */
125#if READBUFFER_SIZE < READBUFFER_MIN
126# error READBUFFER_SIZE is too small
127#endif
129/*
130 * get_protocol_family()
131 *
132 * This is used to return the protocol family for a given protocol.
133 *
134 * Parameters:
135 *
136 * 's' [in] - struct Curl_scheme pointer.
137 *
138 * Returns the family as a single bit protocol identifier.
139 */
140static curl_prot_t get_protocol_family(const struct Curl_scheme *s)
142 DEBUGASSERT(s);
143 DEBUGASSERT(s->family);
144 return s->family;
147void Curl_freeset(struct Curl_easy *data)
149 /* Free all dynamic strings stored in the data->set substructure. */
150 enum dupblob j;
152 CURL_EASY_STR_CLEAR0(data, STRING_PASSWORD);
153 CURL_EASY_STR_CLEAR0(data, STRING_KEY_PASSWD);
154 CURL_EASY_STR_CLEAR0(data, STRING_BEARER);
155#ifndef CURL_DISABLE_PROXY
156 CURL_EASY_STR_CLEAR0(data, STRING_PROXYPASSWORD);
157 CURL_EASY_STR_CLEAR0(data, STRING_KEY_PASSWD_PROXY);
158#endif
159 Curl_u8_strset_clear(&data->set.strings);
160 curlx_safefree(data->set.str_copypostfields);
162 for(j = (enum dupblob)0; j < BLOB_LAST; j++) {
163 curlx_safefree(data->set.blobs[j]);
164 }
166 Curl_bufref_free(&data->state.referer);
167 Curl_bufref_free(&data->state.url);
169#if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API)
170 Curl_mime_cleanpart(data->set.mimepostp);
171 curlx_safefree(data->set.mimepostp);
172#endif
174#ifndef CURL_DISABLE_COOKIES
175 curl_slist_free_all(data->state.cookielist);
176 data->state.cookielist = NULL;
177#endif
180/* free the URL pieces */
181static void up_free(struct Curl_easy *data)
183 struct urlpieces *up = &data->state.up;
184 curlx_safefree(up->options);
185 curlx_safefree(up->path);
186 curlx_safefree(up->query);
187 curl_url_cleanup(data->state.uh);
188 data->state.uh = NULL;
191/*
192 * This is the internal function curl_easy_cleanup() calls. This should
193 * cleanup and free all resources associated with this Curl_easy.
194 *
195 * We ignore SIGPIPE when this is called from curl_easy_cleanup.
196 */
197CURLcode Curl_close(struct Curl_easy **datap)
199 struct Curl_easy *data;
201 if(!datap || !*datap)
202 return CURLE_OK;
204 data = *datap;
205 *datap = NULL;
207 if(!data->state.internal && data->multi) {
208 /* This handle is still part of a multi handle, take care of this first
209 and detach this handle from there.
210 This detaches the connection. */
211 Curl_multi_remove_handle(data->multi, data);
212 }
213 else {
214 /* Detach connection if any is left. This should not be normal, but can be
215 the case for example with CONNECT_ONLY + recv/send (test 556) */
216 Curl_detach_connection(data);
217 if(!data->state.internal && data->multi_easy) {
218 /* when curl_easy_perform() is used, it creates its own multi handle to
219 use and this is the one */
220 curl_multi_cleanup(data->multi_easy);
221 data->multi_easy = NULL;
222 }
223 }
224 DEBUGASSERT(!data->conn || data->state.internal);
226 Curl_expire_clear_all(data); /* shut off any timers left */
228 if(data->state.rangestringalloc)
229 curlx_free(data->state.range);
231 /* release any resolve information this transfer kept */
232 Curl_resolv_destroy_all(data);
234 data->set.verbose = FALSE; /* no more calls to DEBUGFUNCTION */
235 data->magic = 0; /* force a clear AFTER the possibly enforced removal from
236 * the multi handle and async dns shutdown. The multi
237 * handle might check the magic and so might any
238 * DEBUGFUNCTION invoked for tracing */
240 /* freed here in case DONE was not called */
241 Curl_req_free(&data->req, data);
243 /* Close down all open SSL info and sessions */
244 Curl_ssl_close_all(data);
245 Curl_peer_unlink(&data->state.origin);
246 Curl_peer_unlink(&data->state.initial_origin);
247#ifndef CURL_DISABLE_RTSP
248 Curl_peer_unlink(&data->state.rtsp_session_origin);
249#endif
250 Curl_ssl_free_certinfo(data);
252 Curl_bufref_free(&data->state.referer);
254 up_free(data);
255 curlx_dyn_free(&data->state.headerb);
256 Curl_flush_cookies(data, TRUE);
257#ifndef CURL_DISABLE_ALTSVC
258 Curl_altsvc_save(data, data->asi, CURL_EASY_STR(data, STRING_ALTSVC));
259 Curl_altsvc_cleanup(&data->asi);
260#endif
261#ifndef CURL_DISABLE_HSTS
262 Curl_hsts_save(data, data->hsts, CURL_EASY_STR(data, STRING_HSTS));
263 if(!data->share || !data->share->hsts)
264 Curl_hsts_cleanup(&data->hsts);
265 curl_slist_free_all(data->state.hstslist); /* clean up list */
266#endif
267#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
268 Curl_http_auth_cleanup_digest(data);
269#endif
270 curlx_safefree(data->state.most_recent_ftp_entrypath);
271 curlx_safefree(data->info.contenttype);
272 curlx_safefree(data->info.wouldredirect);
273 curlx_safefree(data->info.effective_url);
275 /* No longer a dirty share, if it exists */
276 if(Curl_share_easy_unlink(data))
277 DEBUGASSERT(0);
279 Curl_hash_destroy(&data->meta_hash);
280 Curl_creds_unlink(&data->state.creds);
281#ifndef CURL_DISABLE_HTTP
282 curlx_safefree(data->state.rangeline);
283 curlx_safefree(data->state.http_host);
284#endif
285#ifndef CURL_DISABLE_COOKIES
286 curlx_safefree(data->req.cookiehost);
287#endif
289#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_FORM_API)
290 Curl_mime_cleanpart(data->state.formp);
291 curlx_safefree(data->state.formp);
292#endif
294 /* destruct wildcard structures if it is needed */
295 Curl_wildcard_dtor(&data->wildcard);
296 Curl_freeset(data);
297 Curl_headers_cleanup(data);
298 Curl_netrc_cleanup(&data->state.netrc);
299#ifndef CURL_DISABLE_DIGEST_AUTH
300 curlx_free(data->state.envproxy);
301#endif
302 curlx_memzero(data, sizeof(*data));
303 curlx_free(data);
304 return CURLE_OK;
307/*
308 * Initialize the UserDefined fields within a Curl_easy.
309 * This may be safely called on a new or existing Curl_easy.
310 */
311void Curl_init_userdefined(struct Curl_easy *data)
313 struct UserDefined *set = &data->set;
315 set->out = stdout; /* default output to stdout */
316 set->in_set = stdin; /* default input from stdin */
317 set->err = stderr; /* default stderr to stderr */
319 Curl_u8_strset_init(&data->set.strings);
321#if defined(__clang__) && __clang_major__ >= 16
322#pragma clang diagnostic push
323#pragma clang diagnostic ignored "-Wcast-function-type-strict"
324#endif
325 /* use fwrite as default function to store output */
326 set->fwrite_func = (curl_write_callback)fwrite;
328 /* use fread as default function to read input */
329 set->fread_func_set = (curl_read_callback)fread;
330#if defined(__clang__) && __clang_major__ >= 16
331#pragma clang diagnostic pop
332#endif
333 set->is_fread_set = 0;
335 set->seek_client = ZERO_NULL;
337 set->filesize = -1; /* we do not know the size */
338 set->postfieldsize = -1; /* unknown size */
339 set->maxredirs = 30; /* sensible default */
341 set->method = HTTPREQ_GET; /* Default HTTP request */
342#ifndef CURL_DISABLE_RTSP
343 set->rtspreq = RTSPREQ_OPTIONS; /* Default RTSP request */
344#endif
345#ifndef CURL_DISABLE_FTP
346 set->ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
347 set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
348 set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */
349 set->ftp_filemethod = FTPFILE_MULTICWD;
350 set->ftp_skip_ip = TRUE; /* skip PASV IP by default */
351#endif
352 set->dns_cache_timeout_ms = 60000; /* Timeout every 60 seconds by default */
354 /* Timeout every 24 hours by default */
355 set->ssl_ca_cache_timeout = 24 * 60 * 60;
357 set->httpauth = CURLAUTH_BASIC; /* defaults to basic */
359 Curl_ssl_config_init(&data->set.ssl);
360#ifndef CURL_DISABLE_PROXY
361 Curl_ssl_config_init(&data->set.proxy_ssl);
362 set->proxyport = 0;
363 set->proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
364 set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */
365 /* SOCKS5 proxy auth defaults to username/password + GSS-API */
366 set->socks5auth = CURLAUTH_BASIC | CURLAUTH_GSSAPI;
367#endif
369#ifndef CURL_DISABLE_DOH
370 set->doh_verifyhost = TRUE;
371 set->doh_verifypeer = TRUE;
372#endif
373#ifdef USE_SSH
374 /* defaults to any auth type */
375 set->ssh_auth_types = CURLSSH_AUTH_DEFAULT;
376 set->new_directory_perms = 0755; /* Default permissions */
377#endif
379 set->new_file_perms = 0644; /* Default permissions */
380 set->allowed_protocols = (curl_prot_t)CURLPROTO_64ALL;
381 set->redir_protocols = CURLPROTO_REDIR;
383#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
384 /*
385 * disallow unprotected protection negotiation NEC reference implementation
386 * seem not to follow rfc1961 section 4.3/4.4
387 */
388 set->socks5_gssapi_nec = FALSE;
389#endif
391 /* set default minimum TLS version */
392#ifdef USE_SSL
393 Curl_setopt_SSLVERSION(data, CURLOPT_SSLVERSION, CURL_SSLVERSION_DEFAULT);
394#ifndef CURL_DISABLE_PROXY
395 Curl_setopt_SSLVERSION(data, CURLOPT_PROXY_SSLVERSION,
396 CURL_SSLVERSION_DEFAULT);
397#endif
398#endif
399#ifndef CURL_DISABLE_FTP
400 set->wildcard_enabled = FALSE;
401 set->chunk_bgn = ZERO_NULL;
402 set->chunk_end = ZERO_NULL;
403 set->fnmatch = ZERO_NULL;
404#endif
405 set->tcp_keepalive = FALSE;
406 set->tcp_keepintvl = 60;
407 set->tcp_keepidle = 60;
408 set->tcp_keepcnt = 9;
409 set->tcp_fastopen = FALSE;
410 set->tcp_nodelay = TRUE;
411 set->ssl_enable_alpn = TRUE;
412 set->expect_100_timeout = 1000L; /* Wait for a second by default. */
413 set->sep_headers = TRUE; /* separated header lists by default */
414 set->buffer_size = READBUFFER_SIZE;
415 set->upload_buffer_size = UPLOADBUFFER_DEFAULT;
416 set->upload_flags = CURLULFLAG_SEEN;
417 set->happy_eyeballs_timeout = CURL_HET_DEFAULT;
418 set->upkeep_interval_ms = CURL_UPKEEP_INTERVAL_DEFAULT;
419 set->maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
420 set->conn_max_idle_ms = 118 * 1000;
421 set->conn_max_age_ms = 24 * 3600 * 1000;
422 set->http09_allowed = FALSE;
423 set->httpwant = CURL_HTTP_VERSION_NONE;
424#if defined(USE_HTTP2) || defined(USE_HTTP3)
425 set->weight = 0;
426#endif
427 set->quick_exit = 0L;
428#ifndef CURL_DISABLE_WEBSOCKETS
429 set->ws_raw_mode = FALSE;
430 set->ws_no_auto_pong = FALSE;
431#endif
434/* easy->meta_hash destructor. Should never be called as elements
435 * MUST be added with their own destructor */
436static void easy_meta_freeentry(void *p)
438 (void)p;
439 /* Always FALSE. Cannot use a 0 assert here since compilers
440 * are not in agreement if they then want a NORETURN attribute or
441 * not. *sigh* */
442 DEBUGASSERT(!p);
445/**
446 * Curl_open()
447 *
448 * @param curl is a pointer to a Curl_easy pointer that gets set by this
449 * function.
450 * @return CURLcode
451 */
452CURLcode Curl_open(struct Curl_easy **curl)
454 struct Curl_easy *data;
456 /* simple start-up: alloc the struct, init it with zeroes and return */
457 data = curlx_calloc(1, sizeof(struct Curl_easy));
458 if(!data) {
459 /* this is a serious error */
460 DEBUGF(curl_mfprintf(stderr, "Error: calloc of Curl_easy failed\n"));
461 return CURLE_OUT_OF_MEMORY;
462 }
464 data->magic = CURLEASY_MAGIC_NUMBER;
465 /* most recent connection is not yet defined */
466 data->state.last_conn_id = -1;
467 data->state.last_cpid = UINT32_MAX;
468 /* and not assigned an id yet */
469 data->id = -1;
470 data->mid = UINT32_MAX;
471 data->master_mid = UINT32_MAX;
472 data->progress.hide = TRUE;
474 Curl_hash_init(&data->meta_hash, 23, CURL_HASH_TYPE_BYTES,
475 easy_meta_freeentry);
476 DEBUGASSERT(STRING_LAST <= UINT8_MAX);
477 Curl_u8_strset_init(&data->set.strings);
478 curlx_dyn_init(&data->state.headerb, CURL_MAX_HTTP_HEADER);
479 Curl_bufref_init(&data->state.url);
480 Curl_bufref_init(&data->state.referer);
481 Curl_req_init(&data->req);
482 Curl_initinfo(data);
483#ifndef CURL_DISABLE_HTTP
484 Curl_llist_init(&data->state.httphdrs, NULL);
485#endif
486 Curl_netrc_init(&data->state.netrc);
487 Curl_init_userdefined(data);
489 *curl = data;
490 return CURLE_OK;
493void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn)
495 int8_t i;
497 DEBUGASSERT(conn);
499 if(conn->scheme && conn->scheme->run->disconnect &&
500 !conn->bits.shutdown_handler)
501 conn->scheme->run->disconnect(data, conn, TRUE);
503 for(i = 0; i < (int8_t)CURL_ARRAYSIZE(conn->cfilter); ++i) {
504 Curl_conn_cf_discard_all(data, conn, i);
505 }
507#ifndef CURL_DISABLE_PROXY
508 Curl_peer_unlink(&conn->http_proxy.peer);
509 Curl_peer_unlink(&conn->socks_proxy.peer);
510 Curl_creds_unlink(&conn->http_proxy.creds);
511 Curl_creds_unlink(&conn->socks_proxy.creds);
512#endif
513 Curl_creds_unlink(&conn->creds);
514 Curl_peer_unlink(&conn->creds_origin);
515 curlx_safefree(conn->options);
516 curlx_safefree(conn->interface_opts);
517 Curl_ssl_conn_config_cleanup(conn);
519 curlx_safefree(conn->destination);
520 Curl_hash_destroy(&conn->meta_hash);
521 Curl_peer_unlink(&conn->origin);
522 Curl_peer_unlink(&conn->via_peer);
523 Curl_peer_unlink(&conn->origin2);
524 Curl_peer_unlink(&conn->via_peer2);
526 curlx_free(conn); /* free all the connection oriented data */
529/*
530 * xfer_may_multiplex()
531 *
532 * Return a TRUE, iff the transfer can be done over an (appropriate)
533 * multiplexed connection.
534 */
535static bool xfer_may_multiplex(const struct Curl_easy *data,
536 const struct connectdata *conn)
538#ifndef CURL_DISABLE_HTTP
539 /* If an HTTP protocol and multiplexing is enabled */
540 if((conn->scheme->protocol & PROTO_FAMILY_HTTP) &&
541 (!conn->bits.protoconnstart || !conn->bits.close)) {
543 if(Curl_multiplex_wanted(data->multi) &&
544 (data->state.http_neg.allowed & (CURL_HTTP_V2x | CURL_HTTP_V3x)))
545 /* allows HTTP/2 or newer */
546 return TRUE;
547 }
548#else
549 (void)data;
550 (void)conn;
551#endif
552 return FALSE;
555#ifndef CURL_DISABLE_PROXY
556static bool proxy_info_matches(const struct proxy_info *data,
557 const struct proxy_info *needle)
559 if((data->proxytype == needle->proxytype) &&
560 Curl_peer_same_destination(data->peer, needle->peer) &&
561 Curl_creds_same(data->creds, needle->creds)) {
562 return TRUE;
563 }
564 return FALSE;
566#endif
568#ifdef USE_SSH
569static bool ssh_config_matches(struct connectdata *one,
570 struct connectdata *two)
572 struct ssh_conn *sshc1, *sshc2;
574 sshc1 = Curl_conn_meta_get(one, CURL_META_SSH_CONN);
575 sshc2 = Curl_conn_meta_get(two, CURL_META_SSH_CONN);
576 return sshc1 && sshc2 && Curl_safecmp(sshc1->priv_key, sshc2->priv_key) &&
577 Curl_safecmp(sshc1->pub_key, sshc2->pub_key);
579#endif
581struct url_conn_match {
582 struct connectdata *found;
583 struct Curl_easy *data;
584 struct connectdata *needle;
585 struct curltime now;
586 struct ssl_filter_config ssl_config;
587#ifndef CURL_DISABLE_PROXY
588 struct ssl_filter_config proxy_ssl_config;
589#endif
590 BIT(may_multiplex);
591 BIT(want_nego_http);
592 BIT(want_proxy_nego_http);
593 BIT(may_tls); /* May upgrade clear-text connection to TLS, can only reuse
594 * connections that have matching TLS configuration.
595 * Always TRUE if `req_tls` is TRUE. */
596 BIT(require_tls); /* Requires TLS use from a clear-text start, can only
597 * reuse connections that have TLS. */
598 BIT(wait_pipe);
599 BIT(seen_pending_conn);
600 BIT(seen_single_use_conn);
601 BIT(seen_multiplex_conn);
602};
604static bool url_match_connect_config(struct connectdata *conn,
605 struct url_conn_match *m)
607 /* connect-only or to-be-closed connections will not be reused */
608 if(conn->bits.connect_only || conn->bits.close || conn->bits.no_reuse)
609 return FALSE;
611 /* ip_version must match */
612 if(m->data->set.ipver != CURL_IPRESOLVE_WHATEVER &&
613 m->data->set.ipver != conn->ip_version)
614 return FALSE;
616 /* When needle has specific local bind settings, those have to match.
617 * If it does not, any other connection might do when it comes to ports. */
618 if(m->needle->localport &&
619 ((conn->localport != m->needle->localport) ||
620 (conn->localportrange != m->needle->localportrange)))
621 return FALSE;
622 /* For interface related bind options, we require a full match
623 * as connection might go totally different ways (VPNs, for example). */
624 if((m->needle->interface_opts != conn->interface_opts) &&
625 (!m->needle->interface_opts || !conn->interface_opts ||
626 strcmp(conn->interface_opts, m->needle->interface_opts)))
627 return FALSE;
629 if((m->needle->interface_opts || m->needle->localport) &&
630 /* If we are bound to a specific local end (IP+port), we must not reuse a
631 random other one, although if we did not ask for a particular one we
632 can reuse one that was bound. */
633 ((conn->localport != m->needle->localport) ||
634 (conn->localportrange != m->needle->localportrange) ||
635 (m->needle->interface_opts &&
636 (!conn->interface_opts ||
637 strcmp(conn->interface_opts, m->needle->interface_opts)))))
638 return FALSE;
640 if(!m->needle->via_peer != !conn->via_peer)
641 /* do not mix connections that use the "connect to host" feature and
642 * connections that do not use this feature */
643 return FALSE;
645 return TRUE;
648static bool url_match_fully_connected(struct connectdata *conn,
649 struct url_conn_match *m)
651 if(!Curl_conn_is_connected(conn, FIRSTSOCKET) ||
652 conn->bits.upgrade_in_progress) {
653 /* Not yet connected, or a protocol upgrade is in progress. The later
654 * happens for HTTP/2 Upgrade: requests that need a response. */
655 if(m->may_multiplex) {
656 m->seen_pending_conn = TRUE;
657 /* Do not pick a connection that has not connected yet */
658 infof(m->data, "Connection #%" FMT_OFF_T
659 " is not open enough, cannot reuse", conn->connection_id);
660 }
661 /* Do not pick a connection that has not connected yet */
662 return FALSE;
663 }
664 return TRUE;
667static bool url_match_multi(struct connectdata *conn,
668 struct url_conn_match *m)
670 if(CONN_INUSE(conn)) {
671 DEBUGASSERT(conn->attached_multi);
672 if(conn->attached_multi != m->data->multi)
673 return FALSE;
674 }
675 return TRUE;
678static bool url_match_multiplex_needs(struct connectdata *conn,
679 struct url_conn_match *m)
681 if(CONN_INUSE(conn)) {
682 if(!conn->bits.multiplex) {
683 /* conn busy and conn cannot take more transfers */
684 m->seen_single_use_conn = TRUE;
685 return FALSE;
686 }
687 m->seen_multiplex_conn = TRUE;
688 if(!m->may_multiplex || !url_match_multi(conn, m))
689 /* conn busy and transfer cannot be multiplexed */
690 return FALSE;
691 }
692 return TRUE;
695static bool url_match_multiplex_limits(struct connectdata *conn,
696 struct url_conn_match *m)
698 if(CONN_INUSE(conn) && m->may_multiplex) {
699 DEBUGASSERT(conn->bits.multiplex);
700 /* If multiplexed, make sure we do not go over concurrency limit */
701 if(conn->attached_xfers >=
702 Curl_multi_max_concurrent_streams(m->data->multi)) {
703 infof(m->data, "connection #%" FMT_OFF_T " reached "
704 "MAX_CONCURRENT_STREAMS(%u), skip",
705 conn->connection_id, conn->attached_xfers);
706 return FALSE;
707 }
708 if(conn->attached_xfers >=
709 Curl_conn_get_max_concurrent(m->data, conn, FIRSTSOCKET)) {
710 infof(m->data, "connection #%" FMT_OFF_T "reached "
711 "MAX_CONCURRENT_STREAMS(%u), skip",
712 conn->connection_id, conn->attached_xfers);
713 return FALSE;
714 }
715 /* When not multiplexed, we have a match here! */
716 infof(m->data, "Multiplexed connection found");
717 }
718 return TRUE;
721static bool url_match_ssl_use(struct connectdata *conn,
722 struct url_conn_match *m)
724 if(m->needle->scheme->flags & PROTOPT_SSL) {
725 /* We are looking for SSL, if `conn` does not do it, not a match. */
726 if(!Curl_conn_is_ssl(conn, FIRSTSOCKET))
727 return FALSE;
728 }
729 else if(Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
730 /* If the protocol does not allow reuse of SSL connections OR
731 is of another protocol family, not a match. */
732 if(!(m->needle->scheme->flags & PROTOPT_SSL_REUSE) ||
733 (get_protocol_family(conn->scheme) != m->needle->scheme->protocol))
734 return FALSE;
735 /* We may reuse this as an auto-TLS upgrade, but only if the SSL
736 * config parameters match. */
737 if(!Curl_ssl_conn_config_match(m->data, &m->ssl_config, conn, FALSE))
738 return FALSE;
739 }
740 else if(m->require_tls)
741 /* a clear-text STARTTLS protocol with required TLS */
742 return FALSE;
743 return TRUE;
746#ifndef CURL_DISABLE_PROXY
747static bool url_match_proxy_use(struct connectdata *conn,
748 struct url_conn_match *m)
750 if(m->needle->bits.origin_is_proxy != conn->bits.origin_is_proxy)
751 return FALSE;
753 if(!proxy_info_matches(&m->needle->socks_proxy, &conn->socks_proxy))
754 return FALSE;
756 if(!proxy_info_matches(&m->needle->http_proxy, &conn->http_proxy))
757 return FALSE;
759 if(m->data->set.socks5_auth_only && !conn->bits.socks5_authenticated &&
760 ((conn->socks_proxy.proxytype == CURLPROXY_SOCKS5) ||
761 (conn->socks_proxy.proxytype == CURLPROXY_SOCKS5_HOSTNAME))) {
762 DEBUGF(infof(m->data,
763 "Connection #%" FMT_OFF_T
764 " was not SOCKS5 authenticated, cannot reuse",
765 conn->connection_id));
766 return FALSE;
767 }
769 if(CURL_PROXY_IS_HTTPS(m->needle->http_proxy.proxytype)) {
770 /* https proxies come in different types, http/1.1, h2, ... */
771 /* match SSL config to proxy */
772 if(!Curl_ssl_conn_config_match(m->data, &m->proxy_ssl_config,
773 conn, TRUE)) {
774 DEBUGF(infof(m->data,
775 "Connection #%" FMT_OFF_T
776 " has different SSL proxy parameters, cannot reuse",
777 conn->connection_id));
778 return FALSE;
779 }
780 /* the SSL config to the server, which may apply here is checked
781 * further below */
782 }
783 return TRUE;
785#else
786#define url_match_proxy_use(c, m) ((void)(c), (void)(m), TRUE)
787#endif
789#ifndef CURL_DISABLE_HTTP
790static bool url_match_http_multiplex(struct connectdata *conn,
791 struct url_conn_match *m,
792 bool *pwait_pipe)
794 if(m->may_multiplex &&
795 (m->data->state.http_neg.allowed & (CURL_HTTP_V2x | CURL_HTTP_V3x)) &&
796 (m->needle->scheme->protocol & CURLPROTO_HTTP) &&
797 !conn->httpversion_seen) {
798 if(m->data->set.pipewait) {
799 infof(m->data, "Server upgrade does not support multiplex yet, wait");
800 m->found = NULL;
801 *pwait_pipe = TRUE;
802 return TRUE; /* stop searching, we want to wait */
803 }
804 infof(m->data, "Server upgrade cannot be used");
805 return FALSE;
806 }
807 return TRUE;
810static bool url_match_http_version(struct connectdata *conn,
811 struct url_conn_match *m)
813 /* If looking for HTTP and the HTTP versions allowed do not include
814 * the HTTP version of conn, continue looking. */
815 if((m->needle->scheme->protocol & PROTO_FAMILY_HTTP)) {
816 switch(Curl_conn_http_version(m->data, conn)) {
817 case 30:
818 if(!(m->data->state.http_neg.allowed & CURL_HTTP_V3x)) {
819 DEBUGF(infof(m->data, "not reusing conn #%" CURL_FORMAT_CURL_OFF_T
820 ", we do not want h3", conn->connection_id));
821 return FALSE;
822 }
823 break;
824 case 20:
825 if(!(m->data->state.http_neg.allowed & CURL_HTTP_V2x)) {
826 DEBUGF(infof(m->data, "not reusing conn #%" CURL_FORMAT_CURL_OFF_T
827 ", we do not want h2", conn->connection_id));
828 return FALSE;
829 }
830 break;
831 default:
832 if(!(m->data->state.http_neg.allowed & CURL_HTTP_V1x)) {
833 DEBUGF(infof(m->data, "not reusing conn #%" CURL_FORMAT_CURL_OFF_T
834 ", we do not want h1", conn->connection_id));
835 return FALSE;
836 }
837 break;
838 }
839 }
840 return TRUE;
842#else
843#define url_match_http_multiplex(c, m, w) ((void)(c), (void)(m), TRUE)
844#define url_match_http_version(c, m) ((void)(c), (void)(m), TRUE)
845#endif
847static bool url_match_proto_config(struct connectdata *conn,
848 struct url_conn_match *m)
850 if(!url_match_http_version(conn, m))
851 return FALSE;
853#ifdef USE_SSH
854 if(get_protocol_family(m->needle->scheme) & PROTO_FAMILY_SSH) {
855 if(!ssh_config_matches(m->needle, conn))
856 return FALSE;
857 }
858#endif
859#ifndef CURL_DISABLE_FTP
860 else if(get_protocol_family(m->needle->scheme) & PROTO_FAMILY_FTP) {
861 if(!Curl_ftp_conns_match(m->needle, conn))
862 return FALSE;
863 }
864#endif
865 return TRUE;
868static bool url_match_auth(struct connectdata *conn,
869 struct url_conn_match *m)
871 if(!Curl_creds_same(m->needle->creds, conn->creds)) {
872 if(m->needle->creds)
873 return FALSE;
874 if(!Curl_creds_same(m->data->state.creds, conn->creds))
875 return FALSE;
876 }
877#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
878 /* GSS delegation differences do not actually affect every connection and
879 auth method, but this check takes precaution before efficiency */
880 if(m->needle->gssapi_delegation != conn->gssapi_delegation)
881 return FALSE;
882#endif
884 return TRUE;
887static bool url_match_destination(struct connectdata *conn,
888 struct url_conn_match *m)
890 /* Different connect-to peers never match */
891 if(!Curl_peer_same_destination(m->needle->via_peer, conn->via_peer))
892 return FALSE;
894 if(m->needle->origin->scheme != conn->origin->scheme &&
895 /* `needle` and `conn` not having the same scheme.
896 * This is allowed for the same family *if* conn is using TLS.
897 * - IMAP+STARTTLS works for IMAPS.
898 * - IMAPS works for IMAP. */
899 get_protocol_family(conn->origin->scheme) !=
900 m->needle->scheme->protocol)
901 return FALSE;
903 /* Scheme mismatch is acceptable, compare hostname/port */
904 return Curl_peer_same_destination(m->needle->origin, conn->origin);
907static bool url_match_ssl_config(struct connectdata *conn,
908 struct url_conn_match *m)
910 /* If talking/upgrading to TLS, conn needs to use the same SSL options. */
911 if(((m->needle->scheme->flags & PROTOPT_SSL) || m->may_tls) &&
912 !Curl_ssl_conn_config_match(m->data, &m->ssl_config, conn, FALSE)) {
913 DEBUGF(infof(m->data, "Connection #%" FMT_OFF_T
914 " has different SSL parameters, cannot reuse",
915 conn->connection_id));
916 return FALSE;
917 }
918 return TRUE;
921#ifdef USE_SPNEGO
922static bool url_match_auth_nego(struct connectdata *conn,
923 struct url_conn_match *m)
925 if(conn->http_negotiate_state != CURL_NEGO_AUTH_NONE) {
926 /* Connection is using Negotiate. We cannot reuse if transfer
927 * has different Auth input parameters. */
928 if(!m->want_nego_http ||
929 !Curl_creds_same(conn->creds, m->data->state.creds) ||
930 !Curl_peer_equal(conn->creds_origin, m->data->state.origin))
931 return FALSE;
932 }
933 else if(m->want_nego_http) {
934 /* Transfer wants Negotiate, connection is not using it.
935 * Do not reuse when connection credentials state is bound to an origin
936 * and it or creds differ. */
937 if(conn->creds_origin &&
938 (!Curl_creds_same(conn->creds, m->data->state.creds) ||
939 !Curl_peer_equal(conn->creds_origin, m->data->state.origin)))
940 return FALSE;
941 }
943#ifndef CURL_DISABLE_PROXY
944 /* Same for Proxy Negotiate authentication */
945 if(conn->proxy_negotiate_state != CURL_NEGO_AUTH_NONE) {
946 if(!m->want_proxy_nego_http ||
947 !Curl_creds_same(m->needle->http_proxy.creds, conn->http_proxy.creds))
948 return FALSE;
949 }
950 else if(m->want_proxy_nego_http) {
951 if(conn->http_proxy.creds &&
952 !Curl_creds_same(m->needle->http_proxy.creds, conn->http_proxy.creds))
953 return FALSE;
954 }
955#endif
956 return TRUE;
958#else
959#define url_match_auth_nego(c, m) ((void)(c), (void)(m), TRUE)
960#endif
962static cpool_match_result url_match_conn(struct connectdata *conn,
963 void *userdata)
965 struct url_conn_match *m = userdata;
966 bool wait_pipe = FALSE;
968 /* general connect config setting match? */
969 if(!url_match_connect_config(conn, m))
970 return CPOOL_MATCH_CONT;
972 /* match for destination and protocol? */
973 if(!url_match_destination(conn, m))
974 return CPOOL_MATCH_CONT;
976 if(!url_match_fully_connected(conn, m))
977 return CPOOL_MATCH_CONT;
979 if(!url_match_multiplex_needs(conn, m))
980 return CPOOL_MATCH_CONT;
982 if(!url_match_ssl_use(conn, m))
983 return CPOOL_MATCH_CONT;
985 if(!url_match_proxy_use(conn, m))
986 return CPOOL_MATCH_CONT;
987 if(!url_match_ssl_config(conn, m))
988 return CPOOL_MATCH_CONT;
990 if(!url_match_http_multiplex(conn, m, &wait_pipe))
991 return CPOOL_MATCH_CONT;
993 if(!url_match_auth(conn, m))
994 return CPOOL_MATCH_CONT;
996 if(!url_match_proto_config(conn, m))
997 return CPOOL_MATCH_CONT;
999 if(!url_match_auth_nego(conn, m))
1000 return CPOOL_MATCH_CONT;
1002 if(!url_match_multiplex_limits(conn, m))
1003 return CPOOL_MATCH_CONT;
1005 /* The connection matches all conditions, but do we want to use it? */
1006 if(wait_pipe) {
1007 /* The connection fits, but it's multiplex state has not been determined
1008 * yet. Put the transfer into PENDING and wait for conn state change. */
1009 DEBUGASSERT(!m->found);
1010 m->wait_pipe = TRUE;
1011 return CPOOL_MATCH_FOUND;
1014 if(m->data->set.conn_max_age_ms > 0) {
1015 timediff_t age_ms = Curl_cpool_conn_age_ms(m->data, conn, &m->now);
1016 if(age_ms > m->data->set.conn_max_age_ms) {
1017 /* Transfer is looking for a younger connection. */
1018 return CPOOL_MATCH_TOO_OLD;
1022 /* If we are going to pick an idle connection, do an extra
1023 * health check before we reuse it. */
1024 if(!CONN_INUSE(conn) &&
1025 !Curl_cpool_conn_seems_healthy(conn, m->data, &m->now)) {
1026 infof(m->data, "Connection %" FMT_OFF_T " seems to be dead, terminating",
1027 conn->connection_id);
1028 return CPOOL_MATCH_CLOSE;
1031 /* conn matches our needs. */
1032 m->found = conn;
1033 return CPOOL_MATCH_FOUND;
1036static bool url_match_result(void *userdata)
1038 struct url_conn_match *match = userdata;
1039 if(match->found) {
1040 /* Attach it now while still under lock, so the connection does
1041 * no longer appear idle and can be reaped. */
1042 Curl_attach_connection(match->data, match->found, TRUE);
1043 return TRUE;
1045 else if(match->seen_single_use_conn && !match->seen_multiplex_conn) {
1046 /* We have seen a single-use, existing connection to the destination and
1047 * no multiplexed one. It seems safe to assume that the server does
1048 * not support multiplexing. */
1049 match->wait_pipe = FALSE;
1051 else if(match->seen_pending_conn && match->data->set.pipewait) {
1052 infof(match->data,
1053 "Found pending candidate for reuse and CURLOPT_PIPEWAIT is set");
1054 match->wait_pipe = TRUE;
1056 return FALSE;
1060 * Given a transfer and a prototype connection (needle),
1061 * find and attach an existing connection that matches.
1063 * Return TRUE if an existing connection was attached.
1064 * `waitpipe` is TRUE if no existing connection matched, but there
1065 * might be suitable one in the near future (common cause: multiplexing
1066 * capability has not been determined yet, e.g. ALPN handshake).
1067 */
1068static bool url_attach_existing(struct Curl_easy *data,
1069 struct connectdata *needle,
1070 struct url_conn_match *m,
1071 const struct curltime *pnow)
1073 /* Find a connection in the pool that matches what "data + needle"
1074 * requires. If a suitable candidate is found, it is attached to "data". */
1075 return Curl_cpool_find(data, needle->destination, TRUE, pnow,
1076 url_match_conn, url_match_result, m);
1080 * Allocate and initialize a new connectdata object.
1081 */
1082static struct connectdata *allocate_conn(struct Curl_easy *data)
1084 struct connectdata *conn = curlx_calloc(1, sizeof(struct connectdata));
1085 if(!conn)
1086 return NULL;
1088 /* and we setup a few fields in case we end up actually using this struct */
1089 conn->sock[FIRSTSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
1090 conn->sock[SECONDARYSOCKET] = CURL_SOCKET_BAD; /* no file descriptor */
1091 conn->recv_idx = 0; /* default for receiving transfer data */
1092 conn->send_idx = 0; /* default for sending transfer data */
1093 conn->connection_id = -1; /* no ID */
1094 conn->cpid = UINT32_MAX; /* not in connection pool yet */
1095 conn->attached_xfers = 0;
1096 conn->connect_start_ms = -1;
1097 conn->shutdown.start_ms[FIRSTSOCKET] =
1098 conn->shutdown.start_ms[SECONDARYSOCKET] = -1;
1100#ifndef CURL_DISABLE_FTP
1101 conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
1102 conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
1103#endif
1104 conn->ip_version = data->set.ipver;
1105 conn->bits.connect_only = (bool)data->set.connect_only;
1106 conn->transport_wanted = TRNSPRT_TCP; /* most of them are TCP streams */
1108 /* Store the local bind parameters that will be used for this connection */
1109 if(CURL_EASY_STR(data, STRING_INTERFACE_OPT)) {
1110 conn->interface_opts =
1111 curlx_strdup(CURL_EASY_STR(data, STRING_INTERFACE_OPT));
1112 if(!conn->interface_opts)
1113 goto error;
1115#ifndef CURL_DISABLE_BINDLOCAL
1116 conn->localportrange = data->set.localportrange;
1117 conn->localport = data->set.localport;
1118#endif
1120 /* the close socket stuff needs to be copied to the connection struct as
1121 it may live on without (this specific) Curl_easy */
1122 conn->fclosesocket = data->set.fclosesocket;
1123 conn->closesocket_client = data->set.closesocket_client;
1124#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
1125 conn->gssapi_delegation = data->set.gssapi_delegation;
1126#endif
1127 return conn;
1128error:
1130 curlx_free(conn->interface_opts);
1131 curlx_free(conn);
1132 return NULL;
1135static CURLcode url_set_conn_scheme(struct Curl_easy *data,
1136 struct connectdata *conn)
1138 /* URL scheme is usable for connection when it is
1139 * - allowed
1140 * - not from a redirect or an allowed redirect protocol */
1141 const struct Curl_scheme *scheme = conn->origin->scheme;
1142 if(scheme->run &&
1143 (data->set.allowed_protocols & scheme->protocol) &&
1144 (!data->state.this_is_a_follow ||
1145 (data->set.redir_protocols & scheme->protocol))) {
1146 conn->scheme = scheme;
1147 return CURLE_OK;
1149 if(scheme->flags & PROTOPT_NO_TRANSFER)
1150 failf(data, "Protocol \"%s\" is not for transfers", scheme->name);
1151 else
1152 failf(data, "Protocol \"%s\" is disabled%s", scheme->name,
1153 data->state.this_is_a_follow ? " (in redirect)" : "");
1154 return CURLE_UNSUPPORTED_PROTOCOL;
1157CURLcode Curl_uc_to_curlcode(CURLUcode uc)
1159 switch(uc) {
1160 default:
1161 return CURLE_URL_MALFORMAT;
1162 case CURLUE_UNSUPPORTED_SCHEME:
1163 return CURLE_UNSUPPORTED_PROTOCOL;
1164 case CURLUE_OUT_OF_MEMORY:
1165 return CURLE_OUT_OF_MEMORY;
1166 case CURLUE_USER_NOT_ALLOWED:
1167 return CURLE_LOGIN_DENIED;
1171#ifndef CURL_DISABLE_HSTS
1172static CURLcode hsts_upgrade(struct Curl_easy *data,
1173 CURLU *uh,
1174 uint16_t port_override,
1175 uint32_t scope_id)
1177 /* HSTS upgrade */
1178 if(data->hsts && (data->state.origin->scheme == &Curl_scheme_http) &&
1179 Curl_hsts_applies(data->hsts, data->state.origin)) {
1180 char *url;
1181 CURLUcode uc;
1182 CURLcode result;
1184 uc = curl_url_set(uh, CURLUPART_SCHEME, "https", 0);
1185 if(uc)
1186 return Curl_uc_to_curlcode(uc);
1187 Curl_bufref_free(&data->state.url);
1188 /* after update, get the updated version */
1189 uc = curl_url_get(uh, CURLUPART_URL, &url, 0);
1190 if(uc)
1191 return Curl_uc_to_curlcode(uc);
1192 Curl_bufref_set(&data->state.url, url, 0, curl_free);
1194 result = Curl_peer_from_url(uh, data, port_override, scope_id,
1195 &data->state.origin);
1196 if(result)
1197 return result;
1198 infof(data, "Switched from HTTP to HTTPS due to HSTS => %s", url);
1200 return CURLE_OK;
1202#else
1203#define hsts_upgrade(x, y, z, a) CURLE_OK
1204#endif
1206static bool str_has_ctrl(const char *input)
1208 if(input) {
1209 const unsigned char *str = (const unsigned char *)input;
1210 while(*str) {
1211 if(*str < 0x20)
1212 return TRUE;
1213 str++;
1216 return FALSE;
1219#ifndef CURL_DISABLE_NETRC
1221 * Override the login details from the URL with that in the CURLOPT_USERPWD
1222 * option or a .netrc file, if applicable.
1223 */
1224static CURLcode url_set_data_creds_netrc(struct Curl_easy *data,
1225 struct Curl_creds **pcreds)
1227 struct Curl_creds *ncreds_out = NULL;
1228 CURLcode result = CURLE_OK;
1230 if(data->set.use_netrc) { /* not CURL_NETRC_IGNORED */
1231 struct Curl_creds *ncreds_in = NULL;
1232 bool scan_netrc = TRUE;
1233 NETRCcode ret;
1234 CURLUcode uc;
1236 if(*pcreds) {
1237 switch((*pcreds)->source) {
1238 case CREDS_OPTION:
1239 /* we never override credentials set via CURLOPT_*, leave. */
1240 scan_netrc = FALSE;
1241 break;
1242 case CREDS_URL: /* only apply when netrc is not required */
1243 if(data->set.use_netrc == CURL_NETRC_REQUIRED) {
1244 /* We ignore password from URL */
1245 ncreds_in = *pcreds;
1247 else if(!Curl_creds_has_user(*pcreds) ||
1248 !Curl_creds_has_passwd(*pcreds)) {
1249 /* We use netrc to complete what is missing */
1250 ncreds_in = *pcreds;
1252 else
1253 scan_netrc = FALSE;
1254 break;
1255 default: /* ignore credentials from other sources */
1256 break;
1260 if(!scan_netrc)
1261 goto out;
1263 ret = Curl_netrc_scan(data, &data->state.netrc,
1264 data->state.origin->hostname,
1265 Curl_creds_user(ncreds_in),
1266 CURL_EASY_STR(data, STRING_NETRC_FILE),
1267 &ncreds_out);
1268 DEBUGASSERT(!ret || !ncreds_out);
1269 if(ret == NETRC_OUT_OF_MEMORY) {
1270 result = CURLE_OUT_OF_MEMORY;
1271 goto out;
1273 else if(ret && ((ret == NETRC_NO_MATCH) ||
1274 (data->set.use_netrc == CURL_NETRC_OPTIONAL))) {
1275 infof(data, "Could not find host %s in the %s file; using defaults",
1276 data->state.origin->hostname,
1277 (CURL_EASY_STR(data, STRING_NETRC_FILE) ?
1278 CURL_EASY_STR(data, STRING_NETRC_FILE) : ".netrc"));
1280 else if(ret) {
1281 const char *m = Curl_netrc_strerror(ret);
1282 failf(data, ".netrc error: %s", m);
1283 result = CURLE_READ_ERROR;
1284 goto out;
1286 else if(ncreds_out) {
1287 if(!(data->state.origin->scheme->flags & PROTOPT_USERPWDCTRL) &&
1288 /* if the protocol cannot handle control codes in credentials, make
1289 sure there are none */
1290 (str_has_ctrl(ncreds_out->user) ||
1291 str_has_ctrl(ncreds_out->passwd))) {
1292 failf(data, "control code detected in .netrc credentials");
1293 result = CURLE_READ_ERROR;
1294 goto out;
1296 CURL_TRC_M(data, "netrc: using credentials for %s as %s",
1297 data->state.origin->hostname, ncreds_out->user);
1298 result = Curl_creds_merge(ncreds_out->user, ncreds_out->passwd,
1299 *pcreds, CREDS_NETRC, pcreds);
1300 if(result)
1301 goto out;
1302 /* for updated strings, we update them in the URL */
1303 uc = curl_url_set(data->state.uh, CURLUPART_USER,
1304 Curl_creds_user(*pcreds), CURLU_URLENCODE);
1305 if(!uc)
1306 uc = curl_url_set(data->state.uh, CURLUPART_PASSWORD,
1307 Curl_creds_passwd(*pcreds),
1308 CURLU_URLENCODE);
1309 if(uc)
1310 result = Curl_uc_to_curlcode(uc);
1312 else
1313 DEBUGASSERT(0);
1316#ifdef CURLVERBOSE
1317 Curl_creds_trace(data, data->state.creds, "transfer credentials");
1318#endif
1320out:
1321 Curl_creds_unlink(&ncreds_out);
1322 return result;
1324#endif /* CURL_DISABLE_NETRC */
1326static CURLcode url_set_data_creds(struct Curl_easy *data, CURLU *uh)
1328 struct Curl_creds *newcreds = NULL;
1329 CURLcode result = CURLE_OK;
1331 if((CURL_EASY_STR(data, STRING_USERNAME) ||
1332 CURL_EASY_STR(data, STRING_PASSWORD) ||
1333 CURL_EASY_STR(data, STRING_BEARER) ||
1334 CURL_EASY_STR(data, STRING_SASL_AUTHZID) ||
1335 CURL_EASY_STR(data, STRING_SERVICE_NAME)) &&
1336 Curl_auth_allowed_to_origin(data, data->state.origin)) {
1337 result = Curl_creds_create(CURL_EASY_STR(data, STRING_USERNAME),
1338 CURL_EASY_STR(data, STRING_PASSWORD),
1339 CURL_EASY_STR(data, STRING_BEARER),
1340 CURL_EASY_STR(data, STRING_SASL_AUTHZID),
1341 CURL_EASY_STR(data, STRING_SERVICE_NAME),
1342 CREDS_OPTION, &newcreds);
1343 if(result)
1344 goto out;
1345 if(newcreds &&
1346 !(data->state.origin->scheme->flags & PROTOPT_USERPWDCTRL) &&
1347 (str_has_ctrl(Curl_creds_user(newcreds)) ||
1348 str_has_ctrl(Curl_creds_passwd(newcreds)))) {
1349 /* if the protocol cannot handle control codes in credentials, make
1350 sure there are none */
1351 failf(data, "control code detected in credentials");
1352 result = CURLE_BAD_FUNCTION_ARGUMENT;
1353 goto out;
1357 /* Extract credentials from the URL only if there are none OR
1358 * if no CURLOPT_USER was set. */
1359 if(!newcreds || !Curl_creds_has_user(newcreds)) {
1360 char *user = NULL;
1361 char *passwd = NULL;
1362 char *udecoded = NULL;
1363 char *pdecoded = NULL;
1364 CURLUcode uc;
1366 uc = curl_url_get(uh, CURLUPART_USER, &user, 0);
1367 if(uc && (uc != CURLUE_NO_USER))
1368 result = Curl_uc_to_curlcode(uc);
1369 if(!result) {
1370 uc = curl_url_get(uh, CURLUPART_PASSWORD, &passwd, 0);
1371 if(uc && (uc != CURLUE_NO_PASSWORD))
1372 result = Curl_uc_to_curlcode(uc);
1374 if(!result && user) {
1375 result = Curl_urldecode(user, 0, &udecoded, NULL,
1376 (data->state.origin->scheme->flags &
1377 PROTOPT_USERPWDCTRL) ?
1378 REJECT_ZERO : REJECT_CTRL);
1380 if(!result && passwd) {
1381 result = Curl_urldecode(passwd, 0, &pdecoded, NULL,
1382 (data->state.origin->scheme->flags &
1383 PROTOPT_USERPWDCTRL) ?
1384 REJECT_ZERO : REJECT_CTRL);
1386 if(!result)
1387 result = Curl_creds_merge(udecoded, pdecoded, newcreds,
1388 CREDS_URL, &newcreds);
1390 curlx_free(udecoded);
1391 curlx_free(pdecoded);
1392 curlx_free(passwd);
1393 curlx_free(user);
1394 if(result) {
1395 failf(data, "error extracting credentials from URL");
1396 goto out;
1400#ifndef CURL_DISABLE_NETRC
1401 /* Check for overridden login details and set them accordingly so that
1402 they are known when protocol->setup_connection is called! */
1403 result = url_set_data_creds_netrc(data, &newcreds);
1404#endif /* CURL_DISABLE_NETRC */
1406out:
1407 if(!result && !Curl_creds_equal(data->state.creds, newcreds)) {
1408 /* Do we have more things to trigger on credentials change? */
1409 Curl_creds_link(&data->state.creds, newcreds);
1411 Curl_creds_unlink(&newcreds);
1412 return result;
1415static CURLcode url_set_conn_origin_etc(struct Curl_easy *data,
1416 struct connectdata *conn)
1418 CURLcode result = CURLE_OK;
1420 Curl_peer_link(&conn->origin, data->state.origin);
1422 /* set the connection scheme */
1423 result = url_set_conn_scheme(data, conn);
1424 if(result)
1425 goto out;
1427 /* set the connection options */
1428 if(CURL_EASY_STR(data, STRING_OPTIONS)) {
1429 conn->options = curlx_strdup(CURL_EASY_STR(data, STRING_OPTIONS));
1430 if(!conn->options) {
1431 result = CURLE_OUT_OF_MEMORY;
1432 goto out;
1435 else if(data->state.up.options) {
1436 conn->options = curlx_strdup(data->state.up.options);
1437 if(!conn->options) {
1438 result = CURLE_OUT_OF_MEMORY;
1439 goto out;
1443out:
1444 return result;
1448 * If we are doing a resumed transfer, we need to setup our stuff
1449 * properly.
1450 */
1451static CURLcode setup_range(struct Curl_easy *data)
1453 struct UrlState *s = &data->state;
1454 s->resume_from = data->set.set_resume_from;
1455 if(s->resume_from || CURL_EASY_STR(data, STRING_SET_RANGE)) {
1456 if(s->rangestringalloc)
1457 curlx_free(s->range);
1459 if(s->resume_from)
1460 s->range = curl_maprintf("%" FMT_OFF_T "-", s->resume_from);
1461 else
1462 s->range = curlx_strdup(CURL_EASY_STR(data, STRING_SET_RANGE));
1464 if(!s->range)
1465 return CURLE_OUT_OF_MEMORY;
1467 s->rangestringalloc = TRUE;
1469 /* tell ourselves to fetch this range */
1470 s->use_range = TRUE; /* enable range download */
1472 else
1473 s->use_range = FALSE; /* disable range download */
1475 return CURLE_OK;
1479 * setup_connection_internals() -
1481 * Setup connection internals specific to the requested protocol in the
1482 * Curl_easy. This is inited and setup before the connection is made but
1483 * is about the particular protocol that is to be used.
1485 * This MUST get called after proxy magic has been figured out.
1486 */
1487static CURLcode setup_connection_internals(struct Curl_easy *data,
1488 struct connectdata *conn)
1490 struct Curl_peer *peer = NULL;
1492 if(conn->scheme->run->setup_connection) {
1493 CURLcode result = conn->scheme->run->setup_connection(data, conn);
1494 if(result)
1495 return result;
1498 /* Now create the destination name */
1499 peer = Curl_conn_get_destination(conn, FIRSTSOCKET);
1500 if(!peer)
1501 return CURLE_FAILED_INIT;
1503 /* IPv6 addresses with a scope_id (0 is default == global) have a
1504 * printable representation with a '%<scope_id>' suffix. */
1505 if(peer->ipv6)
1506 if(peer->scopeid)
1507 conn->destination = curl_maprintf("[%s%%%u]:%u",
1508 peer->hostname, peer->scopeid, peer->port);
1509 else
1510 conn->destination = curl_maprintf("[%s]:%u",
1511 peer->hostname, peer->port);
1512 else
1513 conn->destination = curl_maprintf("%s:%u", peer->hostname, peer->port);
1514 if(!conn->destination)
1515 return CURLE_OUT_OF_MEMORY;
1517 Curl_strntolower(conn->destination, conn->destination,
1518 strlen(conn->destination));
1520#ifdef USE_IPV6
1521 if(data->set.scope_id)
1522 conn->scope_id = data->set.scope_id;
1523 else {
1524 peer = Curl_conn_get_first_peer(conn, FIRSTSOCKET);
1525 if(!peer)
1526 return CURLE_FAILED_INIT;
1527 conn->scope_id = peer->scopeid;
1529#endif
1531 return CURLE_OK;
1535 * Curl_parse_login_details()
1537 * This is used to parse a login string for username, password and options in
1538 * the following formats:
1540 * user
1541 * user:password
1542 * user:password;options
1543 * user;options
1544 * user;options:password
1545 * :password
1546 * :password;options
1547 * ;options
1548 * ;options:password
1550 * Parameters:
1552 * login [in] - login string.
1553 * len [in] - length of the login string.
1554 * userp [in/out] - address where a pointer to newly allocated memory
1555 * holding the user will be stored upon completion.
1556 * passwdp [in/out] - address where a pointer to newly allocated memory
1557 * holding the password will be stored upon completion.
1558 * optionsp [in/out] - OPTIONAL address where a pointer to newly allocated
1559 * memory holding the options will be stored upon
1560 * completion.
1562 * Returns CURLE_OK on success.
1563 */
1564CURLcode Curl_parse_login_details(const char *login, const size_t len,
1565 char **userp, char **passwdp,
1566 char **optionsp)
1568 char *ubuf = NULL;
1569 char *pbuf = NULL;
1570 const char *psep = NULL;
1571 const char *osep = NULL;
1572 size_t ulen;
1573 size_t plen;
1574 size_t olen;
1576 DEBUGASSERT(userp);
1577 DEBUGASSERT(passwdp);
1579 /* Attempt to find the password separator */
1580 psep = memchr(login, ':', len);
1582 /* Attempt to find the options separator */
1583 if(optionsp)
1584 osep = memchr(login, ';', len);
1586 /* Calculate the portion lengths */
1587 ulen = (psep ?
1588 (size_t)(osep && psep > osep ? osep - login : psep - login) :
1589 (osep ? (size_t)(osep - login) : len));
1590 plen = (psep ?
1591 (osep && osep > psep ? (size_t)(osep - psep) :
1592 (size_t)(login + len - psep)) - 1 : 0);
1593 olen = (osep ?
1594 (psep && psep > osep ? (size_t)(psep - osep) :
1595 (size_t)(login + len - osep)) - 1 : 0);
1597 /* Clone the user portion buffer, which can be zero length */
1598 ubuf = curlx_memdup0(login, ulen);
1599 if(!ubuf)
1600 goto error;
1602 /* Clone the password portion buffer */
1603 if(psep) {
1604 pbuf = curlx_memdup0(&psep[1], plen);
1605 if(!pbuf)
1606 goto error;
1609 /* Allocate the options portion buffer */
1610 if(optionsp) {
1611 char *obuf = NULL;
1612 if(olen) {
1613 obuf = curlx_memdup0(&osep[1], olen);
1614 if(!obuf)
1615 goto error;
1617 *optionsp = obuf;
1619 *userp = ubuf;
1620 *passwdp = pbuf;
1621 return CURLE_OK;
1622error:
1623 curlx_free(ubuf);
1624 curlx_free(pbuf);
1625 return CURLE_OUT_OF_MEMORY;
1629 * Set the login details so they are available in the connection
1630 */
1631static CURLcode url_set_conn_login(struct Curl_easy *data,
1632 struct connectdata *conn)
1634 /* If our protocol needs a password and we have none, use the defaults */
1635 if((conn->scheme->flags & PROTOPT_NEEDSPWD) && !conn->creds) {
1636 Curl_peer_link(&conn->creds_origin, data->state.origin);
1637 if(data->state.creds)
1638 Curl_creds_link(&conn->creds, data->state.creds);
1639 else
1640 return Curl_creds_create(CURL_DEFAULT_USER, CURL_DEFAULT_PASSWORD,
1641 NULL, NULL, NULL, CREDS_NONE, &conn->creds);
1643 else if(!(conn->scheme->flags & PROTOPT_CREDSPERREQUEST)) {
1644 /* for protocols that do not handle credentials per request,
1645 * the connection credentials are set by the initial transfer. */
1646 Curl_peer_link(&conn->creds_origin, data->state.origin);
1647 Curl_creds_link(&conn->creds, data->state.creds);
1650 return CURLE_OK;
1654 * Parses one "connect to" string in the form:
1655 * "HOST:PORT:CONNECT-TO-HOST:CONNECT-TO-PORT".
1656 */
1657static CURLcode parse_connect_to_string(struct Curl_easy *data,
1658 const struct Curl_peer *dest,
1659 const char *conn_to_line,
1660 struct Curl_peer **pvia_dest)
1662 CURLcode result = CURLE_OK;
1663 const char *ptr = conn_to_line;
1664 bool host_match = FALSE;
1665 bool port_match = FALSE;
1667 *pvia_dest = NULL;
1669 if(*ptr == ':') {
1670 /* an empty hostname always matches */
1671 host_match = TRUE;
1672 ptr++;
1674 else {
1675 /* check whether the URL's hostname matches. Use the URL hostname
1676 * when it was an IPv6 address. Otherwise use the connection's hostname
1677 * that has IDN conversion. */
1678 size_t hlen = strlen(dest->hostname);
1679 host_match = curl_strnequal(ptr, dest->hostname, hlen);
1680 if(!host_match && (dest->user_hostname != dest->hostname)) {
1681 /* hostname was normalized, could be IPv6 or IDN */
1682 hlen = strlen(dest->user_hostname);
1683 host_match = curl_strnequal(ptr, dest->user_hostname, hlen);
1685 host_match = host_match && ptr[hlen] == ':';
1686 if(host_match)
1687 ptr += hlen + 1;
1690 if(host_match) {
1691 if(*ptr == ':') {
1692 /* an empty port always matches */
1693 port_match = TRUE;
1694 ptr++;
1696 else {
1697 /* check whether the URL's port matches */
1698 const char *ptr_next = strchr(ptr, ':');
1699 if(ptr_next) {
1700 curl_off_t port_to_match;
1701 if(!curlx_str_number(&ptr, &port_to_match, 0xffff) &&
1702 ((uint16_t)port_to_match == dest->port)) {
1703 port_match = TRUE;
1705 ptr = ptr_next + 1;
1710 if(host_match && port_match && ptr && *ptr)
1711 result = Curl_peer_from_connect_to(data, dest, ptr, pvia_dest);
1713 return result;
1716/* With `conn->origin` known, determine if we should talk to that
1717 * directly or via another peer. This is the result of inspecting
1718 * the "connect to" slist and "alt-svc" settings. */
1719static CURLcode url_set_conn_peer(struct Curl_easy *data,
1720 struct connectdata *conn)
1722 CURLcode result = CURLE_OK;
1723 struct Curl_peer *origin = conn->origin;
1724 struct Curl_peer *via_peer = NULL;
1725 struct curl_slist *conn_to_entry = data->set.connect_to;
1727 DEBUGASSERT(!conn->via_peer);
1728 Curl_peer_unlink(&conn->via_peer);
1730 while(conn_to_entry && !via_peer) {
1731 result = parse_connect_to_string(data, origin, conn_to_entry->data,
1732 &via_peer);
1733 if(result)
1734 return result;
1735 conn_to_entry = conn_to_entry->next;
1738#ifndef CURL_DISABLE_ALTSVC
1739 if(data->asi && !via_peer &&
1740 ((conn->scheme->protocol == CURLPROTO_HTTPS) ||
1741#ifdef DEBUGBUILD
1742 /* allow debug builds to circumvent the HTTPS restriction */
1743 getenv("CURL_ALTSVC_HTTP")
1744#else
1746#endif
1747 )) {
1748 /* no connect_to match, try alt-svc! */
1749 enum alpnid srcalpnid = ALPN_none;
1750 bool hit = FALSE;
1751 struct altsvc *as = NULL;
1752 int allowed_alpns = ALPN_none;
1753 struct http_negotiation *neg = &data->state.http_neg;
1754 bool same_dest = FALSE;
1756 DEBUGF(infof(data, "Alt-svc check wanted=%x, allowed=%x",
1757 neg->wanted, neg->allowed));
1758#ifdef USE_HTTP3
1759 if(neg->allowed & CURL_HTTP_V3x)
1760 allowed_alpns |= ALPN_h3;
1761#endif
1762#ifdef USE_HTTP2
1763 if(neg->allowed & CURL_HTTP_V2x)
1764 allowed_alpns |= ALPN_h2;
1765#endif
1766 if(neg->allowed & CURL_HTTP_V1x)
1767 allowed_alpns |= ALPN_h1;
1768 allowed_alpns &= (int)data->asi->flags;
1770 DEBUGF(infof(data, "check Alt-Svc for host '%s'", origin->hostname));
1771#ifdef USE_HTTP3
1772 if(!hit && (neg->wanted & CURL_HTTP_V3x)) {
1773 srcalpnid = ALPN_h3;
1774 hit = Curl_altsvc_lookup(data->asi,
1775 origin, ALPN_h3, /* from */
1776 &as /* to */,
1777 allowed_alpns, &same_dest);
1779#endif
1780#ifdef USE_HTTP2
1781 if(!hit && (neg->wanted & CURL_HTTP_V2x) &&
1782 !neg->h2_prior_knowledge) {
1783 srcalpnid = ALPN_h2;
1784 hit = Curl_altsvc_lookup(data->asi,
1785 origin, ALPN_h2, /* from */
1786 &as /* to */,
1787 allowed_alpns, &same_dest);
1789#endif
1790 if(!hit && (neg->wanted & CURL_HTTP_V1x) &&
1791 !neg->only_10) {
1792 srcalpnid = ALPN_h1;
1793 hit = Curl_altsvc_lookup(data->asi,
1794 origin, ALPN_h1, /* from */
1795 &as /* to */,
1796 allowed_alpns, &same_dest);
1799 if(hit && same_dest) {
1800 /* same destination, but more HTTPS version options */
1801 switch(as->dst.alpnid) {
1802 case ALPN_h1:
1803 neg->wanted |= CURL_HTTP_V1x;
1804 neg->preferred = CURL_HTTP_V1x;
1805 break;
1806 case ALPN_h2:
1807 neg->wanted |= CURL_HTTP_V2x;
1808 neg->preferred = CURL_HTTP_V2x;
1809 break;
1810 case ALPN_h3:
1811 neg->wanted |= CURL_HTTP_V3x;
1812 neg->preferred = CURL_HTTP_V3x;
1813 break;
1814 default: /* should not be possible */
1815 break;
1818 else if(hit) {
1819 result = Curl_peer_create(data, conn->origin->scheme,
1820 as->dst.host, as->dst.port,
1821 &via_peer);
1822 if(result)
1823 return result;
1824 infof(data, "Alt-svc connecting from [%s]%s:%u to [%s]%s:%u",
1825 Curl_alpnid2str(srcalpnid), origin->hostname, origin->port,
1826 Curl_alpnid2str(as->dst.alpnid),
1827 via_peer->hostname, via_peer->port);
1828 conn->bits.altused = TRUE;
1829 if(srcalpnid != as->dst.alpnid) {
1830 /* protocol version switch */
1831 switch(as->dst.alpnid) {
1832 case ALPN_h1:
1833 neg->wanted = neg->allowed = CURL_HTTP_V1x;
1834 neg->only_10 = FALSE;
1835 break;
1836 case ALPN_h2:
1837 neg->wanted = neg->allowed = CURL_HTTP_V2x;
1838 break;
1839 case ALPN_h3:
1840 conn->transport_wanted = TRNSPRT_QUIC;
1841 neg->wanted = neg->allowed = CURL_HTTP_V3x;
1842 break;
1843 default: /* should not be possible */
1844 break;
1849#endif
1851 if(via_peer)
1852 conn->via_peer = via_peer;
1854 return result;
1858 * Adjust reused connection settings to the transfer/needle.
1859 */
1860static void url_conn_reuse_adjust(struct Curl_easy *data,
1861 struct connectdata *needle)
1863 struct connectdata *conn = data->conn;
1865 /* get the user+password information from the needle since it may
1866 * be new for this request even when we reuse conn */
1867 if(needle->creds) {
1868 /* use the new username and password though */
1869 Curl_creds_link(&conn->creds, needle->creds);
1872#ifndef CURL_DISABLE_PROXY
1873 /* use the new proxy username and proxy password though */
1874 Curl_creds_link(&conn->http_proxy.creds, needle->http_proxy.creds);
1875 Curl_creds_link(&conn->socks_proxy.creds, needle->socks_proxy.creds);
1876#endif
1878 /* Finding a connection for reuse in the cpool matches, among other
1879 * things on the "remote-relevant" hostname. This is not necessarily
1880 * the authority of the URL, e.g. conn->origin. For example:
1881 * - we use a proxy (not tunneling). we want to send all requests
1882 * that use the same proxy on this connection.
1883 * - we have a "connect-to" setting that may redirect the hostname of
1884 * a new request to the same remote endpoint of an existing conn.
1885 * We want to reuse an existing conn to the remote endpoint.
1886 * Since connection reuse does not match on conn->origin necessarily, we
1887 * switch conn to needle's host settings.
1888 */
1889 Curl_peer_link(&conn->origin, needle->origin);
1890 Curl_peer_link(&conn->via_peer, needle->via_peer);
1891 Curl_peer_link(&conn->origin2, needle->origin2);
1892 Curl_peer_link(&conn->via_peer2, needle->via_peer2);
1895static void conn_meta_freeentry(void *p)
1897 (void)p;
1898 /* Always FALSE. Cannot use a 0 assert here since compilers
1899 * are not in agreement if they then want a NORETURN attribute or
1900 * not. *sigh* */
1901 DEBUGASSERT(!p);
1904static CURLcode url_create_needle(struct Curl_easy *data,
1905 struct connectdata **pneedle)
1907 struct connectdata *needle = NULL;
1908 CURLcode result = CURLE_OK;
1909 bool network_scheme = TRUE; /* almost all are */
1911 /* Allocate a temporary connection data struct (needle) and fill in for
1912 comparison purposes. */
1913 needle = allocate_conn(data);
1914 if(!needle) {
1915 result = CURLE_OUT_OF_MEMORY;
1916 goto out;
1919 /* Do the unfailable inits first, before checks that may early return */
1920 Curl_hash_init(&needle->meta_hash, 23, CURL_HASH_TYPE_BYTES,
1921 conn_meta_freeentry);
1923 /*************************************************************
1924 * Determine `conn->origin` and populate `data->state.up` and
1925 * other URL related properties.
1926 *************************************************************/
1927 result = url_set_conn_origin_etc(data, needle);
1928 if(result)
1929 goto out;
1931 DEBUGASSERT(needle->origin);
1932 network_scheme = !(needle->origin->scheme->flags & PROTOPT_NONETWORK);
1934#ifdef USE_UNIX_SOCKETS
1935 /*************************************************************
1936 * Set UDS first. It overrides "via_peer" and proxy settings.
1937 *************************************************************/
1938 if(network_scheme && CURL_EASY_STR(data, STRING_UNIX_SOCKET_PATH)) {
1939 result = Curl_peer_uds_create(
1940 needle->origin->scheme, CURL_EASY_STR(data, STRING_UNIX_SOCKET_PATH),
1941 (bool)data->set.abstract_unix_socket, &needle->via_peer);
1942 if(result)
1943 goto out;
1945#endif /* USE_UNIX_SOCKETS */
1947 if(network_scheme && !needle->via_peer) {
1948 /*************************************************************
1949 * If the `via_peer` is not already set (via UDS above),
1950 * determine if we talk to `conn->origin` directly or use
1951 * `conn->via_peer` using "connect to" and "alt-svc" properties.
1952 *************************************************************/
1953 result = url_set_conn_peer(data, needle);
1954 if(result)
1955 goto out;
1958 /*************************************************************
1959 * Check whether the host and the "connect to host" are equal.
1960 * Do this after the hostnames have been IDN-converted and
1961 * before initializing the proxy.
1962 *************************************************************/
1963 if(Curl_peer_equal(needle->origin, needle->via_peer)) {
1964 Curl_peer_unlink(&needle->via_peer);
1967#ifndef CURL_DISABLE_PROXY
1968 /* Going via a unix socket ignores any proxy settings */
1969 if(network_scheme &&
1970 (!needle->via_peer || !needle->via_peer->unix_socket)) {
1971 result = Curl_proxy_init_conn(data, needle);
1972 if(result)
1973 goto out;
1975#endif /* CURL_DISABLE_PROXY */
1977 result = url_set_conn_login(data, needle); /* default credentials */
1978 if(result)
1979 goto out;
1981 /*************************************************************
1982 * Setup internals depending on protocol. Needs to be done after
1983 * we figured out what/if proxy to use.
1984 *************************************************************/
1985 result = setup_connection_internals(data, needle);
1986 if(result)
1987 goto out;
1989 if(needle->scheme->flags & PROTOPT_ALPN) {
1990 /* The protocol wants it, so set the bits if enabled in the easy handle
1991 (default) */
1992 if(data->set.ssl_enable_alpn)
1993 needle->bits.tls_enable_alpn = TRUE;
1996 if(network_scheme) {
1997 /* Setup callbacks for network connections */
1998 needle->recv[FIRSTSOCKET] = Curl_cf_recv;
1999 needle->send[FIRSTSOCKET] = Curl_cf_send;
2000 needle->recv[SECONDARYSOCKET] = Curl_cf_recv;
2001 needle->send[SECONDARYSOCKET] = Curl_cf_send;
2002 needle->bits.tcp_fastopen = data->set.tcp_fastopen;
2003#ifdef USE_UNIX_SOCKETS
2004 if(Curl_conn_get_first_peer(needle, FIRSTSOCKET)->unix_socket)
2005 needle->transport_wanted = TRNSPRT_UNIX;
2006#endif
2009out:
2010 if(!result) {
2011 DEBUGASSERT(needle);
2012 DEBUGASSERT(needle->origin);
2013 *pneedle = needle;
2015 else {
2016 *pneedle = NULL;
2017 if(needle)
2018 Curl_conn_free(data, needle);
2020 return result;
2023static CURLcode url_set_data_origin_and_creds(struct Curl_easy *data)
2025 CURLcode result = CURLE_OK;
2026 CURLU *uh;
2027 CURLUcode uc = CURLUE_OK;
2028 bool use_set_uh = (data->set.uh && !data->state.this_is_a_follow);
2029 uint16_t port_override = data->state.allow_port ? data->set.use_port : 0;
2030 uint32_t scope_id = 0;
2032 /*************************************************************
2033 * Check input data
2034 *************************************************************/
2035 if(!Curl_bufref_ptr(&data->state.url)) {
2036 result = CURLE_URL_MALFORMAT;
2037 goto out;
2040 up_free(data); /* cleanup previous leftovers first */
2042 /* parse the URL */
2043 if(use_set_uh)
2044 uh = data->state.uh = curl_url_dup(data->set.uh);
2045 else
2046 uh = data->state.uh = curl_url();
2047 if(!uh) {
2048 result = CURLE_OUT_OF_MEMORY;
2049 goto out;
2052 if(!use_set_uh) {
2053 bool prepend_sheme = FALSE;
2054 /* special-case when 'file' is default as a normal path is not a valid URL
2055 without the 'file' scheme present */
2056 if(curl_strequal("file", CURL_EASY_STR(data, STRING_DEFAULT_PROTOCOL)) &&
2057 !Curl_is_absolute_url(Curl_bufref_ptr(&data->state.url), NULL, 0, TRUE))
2058 prepend_sheme = TRUE;
2059 else {
2060 uc = curl_url_set(uh, CURLUPART_URL, Curl_bufref_ptr(&data->state.url),
2061 (unsigned int)
2062 CURLU_GUESS_SCHEME |
2063 CURLU_NON_SUPPORT_SCHEME |
2064 (data->set.disallow_username_in_url ?
2065 CURLU_DISALLOW_USER : 0) |
2066 (data->set.path_as_is ? CURLU_PATH_AS_IS : 0));
2067 if(uc) {
2068 failf(data, "URL rejected: %s", curl_url_strerror(uc));
2069 result = Curl_uc_to_curlcode(uc);
2070 goto out;
2073 if(CURL_EASY_STR(data, STRING_DEFAULT_PROTOCOL)) {
2074 /* check if we there was a scheme provided */
2075 char *scheme;
2076 uc = curl_url_get(uh, CURLUPART_SCHEME, &scheme,
2077 CURLU_NO_GUESS_SCHEME);
2078 if(uc == CURLUE_NO_SCHEME)
2079 prepend_sheme = TRUE;
2080 curl_free(scheme);
2081 if(uc && uc != CURLUE_NO_SCHEME) {
2082 result = Curl_uc_to_curlcode(uc);
2083 goto out;
2088 if(prepend_sheme) {
2089 char *url = curl_maprintf("%s://%s",
2090 CURL_EASY_STR(data, STRING_DEFAULT_PROTOCOL),
2091 Curl_bufref_ptr(&data->state.url));
2092 if(!url) {
2093 result = CURLE_OUT_OF_MEMORY;
2094 goto out;
2096 uc = curl_url_set(uh, CURLUPART_URL, url,
2097 (unsigned int)
2098 CURLU_GUESS_SCHEME |
2099 CURLU_NON_SUPPORT_SCHEME |
2100 (data->set.disallow_username_in_url ?
2101 CURLU_DISALLOW_USER : 0) |
2102 (data->set.path_as_is ? CURLU_PATH_AS_IS : 0));
2103 curl_free(url);
2104 if(uc) {
2105 failf(data, "URL rejected: %s", curl_url_strerror(uc));
2106 result = Curl_uc_to_curlcode(uc);
2107 goto out;
2111 char *newurl;
2112 /* after it was parsed, and possibly given a new scheme, get the
2113 normalized version */
2114 uc = curl_url_get(uh, CURLUPART_URL, &newurl, CURLU_GET_EMPTY);
2115 if(uc) {
2116 result = Curl_uc_to_curlcode(uc);
2117 goto out;
2119 if(prepend_sheme)
2120 infof(data, "Applied default protocol '%s'",
2121 CURL_EASY_STR(data, STRING_DEFAULT_PROTOCOL));
2122 Curl_bufref_set(&data->state.url, newurl, 0, curl_free);
2126#ifdef USE_IPV6
2127 scope_id = data->set.scope_id;
2128#endif
2130 /* `uh` is now as the connection should use it, probably. */
2131 result = Curl_peer_from_url(uh, data, port_override, scope_id,
2132 &data->state.origin);
2133 if(result)
2134 goto out;
2135 /* The origin might get changed when HSTS applies */
2136 result = hsts_upgrade(data, uh, port_override, scope_id);
2137 if(result)
2138 goto out;
2140 /* When the transfers initial_origin is not set, this is the initial
2141 * request. Remember this starting point. */
2142 if(!data->state.initial_origin)
2143 Curl_peer_link(&data->state.initial_origin, data->state.origin);
2145 uc = curl_url_get(uh, CURLUPART_PATH, &data->state.up.path, CURLU_URLENCODE);
2146 if(uc) {
2147 result = Curl_uc_to_curlcode(uc);
2148 goto out;
2150 uc = curl_url_get(uh, CURLUPART_QUERY, &data->state.up.query,
2151 CURLU_GET_EMPTY);
2152 if(uc && (uc != CURLUE_NO_QUERY)) {
2153 result = CURLE_OUT_OF_MEMORY;
2154 goto out;
2157 uc = curl_url_get(uh, CURLUPART_OPTIONS, &data->state.up.options,
2158 CURLU_URLDECODE);
2159 if(uc && (uc != CURLUE_NO_OPTIONS)) {
2160 result = Curl_uc_to_curlcode(uc);
2161 goto out;
2164 result = url_set_data_creds(data, uh);
2165 if(result)
2166 goto out;
2168out:
2169 return result;
2172static CURLcode url_match_init(struct Curl_easy *data,
2173 struct connectdata *needle,
2174 struct url_conn_match *m)
2176 memset(m, 0, sizeof(*m));
2177 m->data = data;
2178 m->needle = needle;
2179 m->now = *Curl_pgrs_now(data);
2180 m->may_multiplex = xfer_may_multiplex(data, needle);
2182#if !defined(CURL_DISABLE_HTTP) && defined(USE_SPNEGO)
2183 m->want_nego_http =
2184 (data->state.authhost.want & CURLAUTH_NEGOTIATE) &&
2185 (needle->scheme->protocol & PROTO_FAMILY_HTTP) &&
2186 Curl_auth_allowed_to_host(data);
2187#ifndef CURL_DISABLE_PROXY
2188 m->want_proxy_nego_http =
2189 needle->http_proxy.creds &&
2190 (data->state.authproxy.want & CURLAUTH_NEGOTIATE) &&
2191 (needle->scheme->protocol & PROTO_FAMILY_HTTP);
2192#endif
2193#endif
2194 m->require_tls = data->set.use_ssl >= CURLUSESSL_CONTROL;
2195 m->may_tls = data->set.use_ssl > CURLUSESSL_NONE;
2197 /* Get a shallow setup of filter configs for connection cache matching */
2198 return Curl_ssl_filter_config_tmp_init(data, needle->origin,
2199 &m->ssl_config,
2200#ifndef CURL_DISABLE_PROXY
2201 &m->proxy_ssl_config);
2202#else
2203 NULL);
2204#endif
2207static void url_match_destroy(struct url_conn_match *m)
2209 Curl_ssl_config_cleanup(&m->ssl_config);
2210#ifndef CURL_DISABLE_PROXY
2211 Curl_ssl_config_cleanup(&m->proxy_ssl_config);
2212#endif
2215/**
2216 * Find an existing connection for the transfer or create a new one.
2217 * Returns
2218 * - CURLE_OK on success with a connection attached to data
2219 * - CURLE_NO_CONNECTION_AVAILABLE when connection limits apply or when
2220 * a suitable connection has not determined its multiplex capability.
2221 * - a fatal error
2222 */
2223static CURLcode url_find_or_create_conn(struct Curl_easy *data,
2224 const struct curltime *pnow)
2226 struct connectdata *needle = NULL;
2227 struct url_conn_match match;
2228 bool match_initialized = FALSE;
2229 CURLcode result;
2231 /* create the template connection for transfer data. Use this needle to
2232 * find an existing connection or, if none exists, convert needle
2233 * to a full connection and attach it to data. */
2234 result = url_create_needle(data, &needle);
2235 if(result)
2236 goto out;
2237 DEBUGASSERT(needle);
2239 result = url_match_init(data, needle, &match);
2240 if(result)
2241 goto out;
2242 match_initialized = TRUE;
2244 /***********************************************************************
2245 * file: is a special case in that it does not need a network connection
2246 ***********************************************************************/
2247#ifndef CURL_DISABLE_FILE
2248 if(needle->scheme->flags & PROTOPT_NONETWORK) {
2249 bool done;
2250 /* this is supposed to be the connect function so we better at least check
2251 that the file is present here! */
2252 DEBUGASSERT(needle->scheme->run->connect_it);
2253 data->info.conn_scheme = needle->scheme->name;
2254 /* conn_protocol can only provide "old" protocols */
2255 data->info.conn_protocol = needle->scheme->protocol & CURLPROTO_MASK;
2256 result = needle->scheme->run->connect_it(data, &done);
2257 if(result)
2258 goto out;
2260 /* Setup a "faked" transfer that will do nothing */
2261 result = Curl_cpool_add(data, needle, 0, 0, pnow);
2262 Curl_attach_connection(data, needle, TRUE);
2263 needle = NULL;
2264 if(!result) {
2265 /* Setup whatever necessary for a resumed transfer */
2266 result = setup_range(data);
2267 if(!result) {
2268 Curl_xfer_setup_nop(data);
2269 result = Curl_init_transfer(data, data->conn);
2273 if(result) {
2274 DEBUGASSERT(data->conn->scheme->run->done);
2275 /* we ignore the return code for the protocol-specific DONE */
2276 (void)data->conn->scheme->run->done(data, result, FALSE);
2278 goto out;
2280#endif
2282 /*************************************************************
2283 * Reuse of existing connection is not allowed when
2284 * - connect_only is set or
2285 * - reuse_fresh is set and this is not a follow-up request
2286 * (like with HTTP followlocation)
2287 *************************************************************/
2288 if((!data->set.reuse_fresh || data->state.followlocation) &&
2289 !data->set.connect_only) {
2290 /* Ok, try to find and attach an existing one */
2291 if(url_attach_existing(data, needle, &match, pnow)) {
2292 /* We attached an existing connection for this transfer. Copy
2293 * over transfer specific properties over from needle. */
2294 struct connectdata *conn = data->conn;
2295 VERBOSE(bool tls_upgraded =
2296 (!(needle->origin->scheme->flags & PROTOPT_SSL) &&
2297 Curl_conn_is_ssl(conn, FIRSTSOCKET)));
2299 DEBUGASSERT(conn);
2300 conn->bits.reuse = TRUE;
2301 url_conn_reuse_adjust(data, needle);
2303#ifndef CURL_DISABLE_PROXY
2304 infof(data, "Reusing existing %s: connection%s with %s %s",
2305 conn->origin->scheme->name,
2306 tls_upgraded ? " (upgraded to SSL)" : "",
2307 (conn->socks_proxy.peer || conn->http_proxy.peer) ?
2308 "proxy" : "host",
2309 conn->socks_proxy.peer ? conn->socks_proxy.peer->user_hostname :
2310 conn->http_proxy.peer ? conn->http_proxy.peer->user_hostname :
2311 conn->origin->hostname);
2312#else
2313 infof(data, "Reusing existing %s: connection%s with host %s",
2314 conn->origin->scheme->name,
2315 tls_upgraded ? " (upgraded to SSL)" : "",
2316 conn->origin->hostname);
2317#endif
2321 if(!data->conn) {
2322 /* We have not attached an existing connection. `needle` may become
2323 * the connection to use, if
2324 * - we are not waiting on an existing connection result
2325 * - the total/host limits on active connections allow it
2326 */
2327 if(match.wait_pipe) {
2328 /* There is a connection that *might* become usable for multiplexing
2329 "soon", and we wait for that */
2330 infof(data, "Waiting on connection to negotiate possible multiplexing.");
2331 result = CURLE_NO_CONNECTION_AVAILABLE;
2332 goto out;
2335 /* Add needle to conn pool, observing the limits.
2336 * Initializes connection_id.
2337 * May fail due to limits with CURLE_NO_CONNECTION_AVAILABLE. */
2338 result = Curl_cpool_add(data, needle,
2339 data->multi->max_total_connections,
2340 data->multi->max_host_connections,
2341 pnow);
2342 if(result)
2343 goto out;
2345 /* All fine, attach it and forget needle */
2346 Curl_attach_connection(data, needle, TRUE);
2347 needle = NULL;
2349 /* Clone the SSL filter configs into the new connection. */
2350 result = Curl_ssl_conn_config_clone(&match.ssl_config,
2351#ifndef CURL_DISABLE_PROXY
2352 &match.proxy_ssl_config,
2353#else
2354 NULL,
2355#endif
2356 data->conn);
2357 if(result) {
2358 DEBUGF(infof(data, "Error: clone connection SSL config"));
2359 goto out;
2363 /* COMMON setup code for reused and new connections from here on. */
2365 /* Setup and init stuff before DO starts, in preparing for the transfer. */
2366 result = Curl_init_transfer(data, data->conn);
2367 if(result)
2368 goto out;
2370 /* Setup whatever necessary for a resumed transfer */
2371 result = setup_range(data);
2372 if(result)
2373 goto out;
2375 /* persist the scheme and handler the transfer is using */
2376 data->info.conn_scheme = data->conn->scheme->name;
2377 /* conn_protocol can only provide "old" protocols */
2378 data->info.conn_protocol = data->conn->scheme->protocol & CURLPROTO_MASK;
2379 data->info.used_proxy =
2380#ifdef CURL_DISABLE_PROXY
2382#else
2383 (data->conn->socks_proxy.peer || data->conn->http_proxy.peer)
2384#endif
2387 /* Lastly, inform connection filters that a new transfer is attached */
2388 result = Curl_conn_ev_data_setup(data);
2390out:
2391 if(match_initialized)
2392 url_match_destroy(&match);
2393 if(needle)
2394 Curl_conn_free(data, needle);
2395 DEBUGASSERT(result || data->conn);
2396 return result;
2399CURLcode Curl_connect(struct Curl_easy *data, bool *pconnected)
2401 CURLcode result;
2402 struct connectdata *conn = NULL;
2403 const struct curltime *pnow = NULL;
2404 *pconnected = FALSE;
2406 /* Set the request to virgin state based on transfer settings */
2407 Curl_req_hard_reset(&data->req, data);
2408 /* Determine the origin of the transfer and what credentials to use */
2409 result = url_set_data_origin_and_creds(data);
2410 if(result)
2411 goto out;
2412 if(!data->state.origin) { /* just make really sure */
2413 DEBUGASSERT(0);
2414 result = CURLE_FAILED_INIT;
2415 goto out;
2418 /* Get or create a connection for the transfer. */
2419 pnow = Curl_pgrs_now(data);
2420 Curl_pgrsTimeWas(data, TIMER_POSTQUEUE, *pnow);
2421 result = url_find_or_create_conn(data, pnow);
2422 conn = data->conn;
2423 if(result)
2424 goto out;
2425 if(!data->conn) { /* just make really sure */
2426 DEBUGASSERT(0);
2427 result = CURLE_FAILED_INIT;
2428 goto out;
2431 if(conn->bits.reuse) {
2432 if(conn->attached_xfers > 1)
2433 /* multiplexed */
2434 *pconnected = TRUE;
2436 else if(conn->scheme->flags & PROTOPT_NONETWORK) {
2437 Curl_pgrsTime(data, TIMER_NAMELOOKUP);
2438 *pconnected = TRUE;
2440 else {
2441 result = Curl_conn_setup(data, conn, FIRSTSOCKET, CURL_CF_SSL_DEFAULT);
2442 if(!result)
2443 result = Curl_headers_init(data);
2444 CURL_TRC_M(data, "Curl_conn_setup() -> %d", (int)result);
2447out:
2448 if(result == CURLE_NO_CONNECTION_AVAILABLE)
2449 DEBUGASSERT(!conn);
2451 if(result && conn) {
2452 /* Detach on error and close the connection if
2453 * - it was not reused (meaning, ok before we picked it)
2454 * - there are no other transfers attached to it */
2455 Curl_detach_connection(data);
2456 if(!conn->bits.reuse && !CONN_INUSE(conn))
2457 Curl_conn_close(data, conn, TRUE);
2460 return result;
2464 * Curl_init_transfer() is called each time before the transfer starts - to
2465 * prepare for a transfer, sometimes multiple times on the same Curl_easy.
2466 * Make sure nothing in here depends on stuff that is setup dynamically for
2467 * the transfer.
2469 * Allow this function to get called with 'conn' set to NULL.
2470 */
2472CURLcode Curl_init_transfer(struct Curl_easy *data, struct connectdata *conn)
2474 CURLcode result;
2476 if(conn) {
2477 conn->bits.do_more = FALSE; /* by default there is no curl_do_more() to
2478 use */
2479 /* if the protocol used does not support wildcards, switch it off */
2480 if(data->state.wildcardmatch &&
2481 !(conn->scheme->flags & PROTOPT_WILDCARD))
2482 data->state.wildcardmatch = FALSE;
2485 data->state.done = FALSE; /* *_done() is not called yet */
2487 data->req.no_body = data->set.opt_no_body;
2488 if(data->req.no_body)
2489 /* in HTTP lingo, no body means using the HEAD request... */
2490 data->state.httpreq = HTTPREQ_HEAD;
2492 result = Curl_req_start(&data->req, data);
2493 if(!result) {
2494 Curl_pgrsReset(data);
2496 return result;
2499#if defined(USE_HTTP2) || defined(USE_HTTP3)
2501void Curl_data_priority_clear_state(struct Curl_easy *data)
2503 data->state.weight = 0;
2506#endif /* USE_HTTP2 || USE_HTTP3 */
2508CURLcode Curl_conn_meta_set(struct connectdata *conn, const char *key,
2509 void *meta_data, Curl_meta_dtor *meta_dtor)
2511 if(!Curl_hash_add2(&conn->meta_hash, key, strlen(key) + 1,
2512 meta_data, meta_dtor)) {
2513 meta_dtor(key, strlen(key) + 1, meta_data);
2514 return CURLE_OUT_OF_MEMORY;
2516 return CURLE_OK;
2519void Curl_conn_meta_remove(struct connectdata *conn, const char *key)
2521 Curl_hash_delete(&conn->meta_hash, key, strlen(key) + 1);
2524void *Curl_conn_meta_get(struct connectdata *conn, const char *key)
2526 return Curl_hash_pick(&conn->meta_hash, key, strlen(key) + 1);
2529struct Curl_easy *Curl_get_admin(struct Curl_easy *data)
2531 struct Curl_easy *admin;
2533 if(!data->mid) /* already an admin handle */
2534 admin = data;
2535 else if(data->multi)
2536 admin = data->multi->admin;
2537 else if(data->multi_easy)
2538 admin = data->multi_easy->admin;
2539 else {
2540 DEBUGASSERT(0); /* we do not want this. does it happen? */
2541 admin = data;
2543 if(admin != data) {
2544 admin->set.conn_max_idle_ms = data->set.conn_max_idle_ms;
2545 admin->set.conn_max_age_ms = data->set.conn_max_age_ms;
2546 admin->set.upkeep_interval_ms = data->set.upkeep_interval_ms;
2547 admin->set.timeout = data->set.timeout;
2548 admin->set.server_response_timeout = data->set.server_response_timeout;
2549 admin->set.no_signal = data->set.no_signal;
2551 return admin;
2554CURLcode Curl_1st_fatal(CURLcode r1, CURLcode r2)
2556 if(r1 && (r1 != CURLE_AGAIN))
2557 return r1;
2558 if(r2 && (r2 != CURLE_AGAIN))
2559 return r2;
2560 return r1;
Diagnostics4 git calls · 234 ms
CallStatusSizeTime0234 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=225
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
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=86
Open pack map
fetch20024 KiB229 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=24193
git.response.cache=MISS
git.response.duration_ms=229
git.fetch.wants=8f98c332586ac3cabfad3bf58dbdda131d28d72e
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=24193
git.pkt.payload.max=24172
git.sideband.band1.bytes=24171
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
a5e14b118a86a140
Request
4e230428…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format