Artifactspublic-v0

curl

master
ply4 git calls34 ms298 KiB3 cachedprotocol v2
1259 lines41 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 "tool_setup.h"
26#include "tool_cfgable.h"
27#include "tool_setopt.h"
28#include "tool_findfile.h"
29#include "tool_formparse.h"
30#include "tool_msgs.h"
31#include "tool_libinfo.h"
32#include "tool_cb_soc.h"
33#include "tool_operate.h"
34#include "config2setopts.h"
35#include "tool_ipfs.h"
36#include "tool_cb_wrt.h"
37#include "tool_cb_rea.h"
38#include "tool_cb_see.h"
39#include "tool_cb_dbg.h"
40#include "tool_helpers.h"
41#include "tool_paramhlp.h"
42#include "tool_version.h"
44#ifdef HAVE_NETINET_IN_H
45#include <netinet/in.h> /* IPPROTO_IPV6 */
46#endif
48#define BUFFER_SIZE 102400L
50/* return TRUE if the error code is "lethal" */
51static bool setopt_bad(CURLcode result)
53 return result &&
54 (result != CURLE_NOT_BUILT_IN) &&
55 (result != CURLE_UNKNOWN_OPTION);
58#ifdef IP_TOS
59static int get_address_family(curl_socket_t sockfd)
61 struct sockaddr addr;
62 curl_socklen_t addrlen = sizeof(addr);
63 memset(&addr, 0, sizeof(addr));
64 if(getsockname(sockfd, &addr, &addrlen) == 0)
65 return addr.sa_family;
66 return AF_UNSPEC;
68#endif
70#ifndef SOL_IP
71#define SOL_IP IPPROTO_IP
72#endif
74#if defined(IP_TOS) || defined(IPV6_TCLASS) || defined(SO_PRIORITY)
75static int sockopt_callback(void *clientp, curl_socket_t curlfd,
76 curlsocktype purpose)
78 struct OperationConfig *config = (struct OperationConfig *)clientp;
79 if(purpose != CURLSOCKTYPE_IPCXN)
80 return CURL_SOCKOPT_OK;
81 (void)config;
82 (void)curlfd;
83#if defined(IP_TOS) || defined(IPV6_TCLASS)
84 if(config->ip_tos > 0) {
85 int tos = (int)config->ip_tos;
86 int result = 0;
87 switch(get_address_family(curlfd)) {
88 case AF_INET:
89#ifdef IP_TOS
90 result = setsockopt(curlfd, SOL_IP, IP_TOS, (void *)&tos, sizeof(tos));
91#endif
92 break;
93#if defined(IPV6_TCLASS) && defined(AF_INET6)
94 case AF_INET6:
95 result = setsockopt(curlfd, IPPROTO_IPV6, IPV6_TCLASS,
96 (void *)&tos, sizeof(tos));
97 break;
98#endif
99 }
100 if(result < 0) {
101 char buffer[STRERROR_LEN];
102 int error = errno;
103 warnf("Setting type of service to %d failed with errno %d: %s", tos,
104 error, curlx_strerror(error, buffer, sizeof(buffer)));
105 }
106 }
107#endif
108#ifdef SO_PRIORITY
109 if(config->vlan_priority > 0) {
110 int priority = (int)config->vlan_priority;
111 if(setsockopt(curlfd, SOL_SOCKET, SO_PRIORITY,
112 (void *)&priority, sizeof(priority)) != 0) {
113 char buffer[STRERROR_LEN];
114 int error = errno;
115 warnf("VLAN priority %d failed with errno %d: %s", priority,
116 error, curlx_strerror(error, buffer, sizeof(buffer)));
117 }
118 }
119#endif
120 return CURL_SOCKOPT_OK;
122#endif /* IP_TOD || IPV6_TCLASS || SO_PRIORITY */
124/* return current SSL backend name, chop off multissl */
125static char *ssl_backend(void)
127 static char ssl_ver[80] = "no ssl";
128 static bool already = FALSE;
129 if(!already) { /* if there is no existing version */
130 const char *v = curl_version_info(CURLVERSION_NOW)->ssl_version;
131 if(v)
132 curl_msnprintf(ssl_ver, sizeof(ssl_ver),
133 "%.*s", (int)strcspn(v, " "), v);
134 already = TRUE;
135 }
136 return ssl_ver;
139/*
140 * Possibly rewrite the URL for IPFS and return the protocol token for the
141 * scheme used in the given URL.
142 */
143static CURLcode url_proto_and_rewrite(char **url,
144 struct OperationConfig *config,
145 const char **scheme)
147 CURLcode result = CURLE_OK;
148 CURLU *uh = curl_url();
149 const char *proto = NULL;
150 *scheme = NULL;
152 DEBUGASSERT(url && *url);
153 if(uh) {
154 char *schemep = NULL;
155 CURLUcode uc =
156 curl_url_set(uh, CURLUPART_URL, *url,
157 CURLU_GUESS_SCHEME | CURLU_NON_SUPPORT_SCHEME);
158 if(!uc) {
159 if(config->proto_default) {
160 /* when a default proto is requested, do not guess */
161 uc = curl_url_get(uh, CURLUPART_SCHEME, &schemep,
162 CURLU_NO_GUESS_SCHEME);
163 if(uc == CURLUE_NO_SCHEME) {
164 /* use the default */
165 proto = proto_token(config->proto_default);
166 if(proto)
167 uc = CURLUE_OK;
168 }
169 }
170 else {
171 uc = curl_url_get(uh, CURLUPART_SCHEME, &schemep,
172 CURLU_DEFAULT_SCHEME);
173 }
174 if(schemep)
175 proto = proto_token(schemep);
176#ifndef CURL_DISABLE_IPFS
177 if(!uc &&
178 (curl_strequal(schemep, proto_ipfs) ||
179 curl_strequal(schemep, proto_ipns))) {
180 result = ipfs_url_rewrite(uh, schemep, url, config);
181 /* short-circuit proto_token, we know it is ipfs or ipns */
182 if(curl_strequal(schemep, proto_ipfs))
183 proto = proto_ipfs;
184 else if(curl_strequal(schemep, proto_ipns))
185 proto = proto_ipns;
186 if(result)
187 config->synthetic_error = TRUE;
188 }
189#endif /* !CURL_DISABLE_IPFS */
190 if(uc == CURLUE_OUT_OF_MEMORY)
191 result = CURLE_OUT_OF_MEMORY;
192 curl_free(schemep);
193 }
194 else if(uc == CURLUE_OUT_OF_MEMORY)
195 result = CURLE_OUT_OF_MEMORY;
196 curl_url_cleanup(uh);
197 }
198 else
199 result = CURLE_OUT_OF_MEMORY;
201 *scheme = proto ? proto : "?"; /* Never match if not found. */
202 return result;
205static CURLcode ssh_setopts(struct OperationConfig *config, CURL *curl)
207 CURLcode result;
209 if(!proto_scp && !proto_sftp)
210 return CURLE_OK;
212 /* SSH and SSL private key uses same command-line option */
213 MY_SETOPT_STR(curl, CURLOPT_SSH_PRIVATE_KEYFILE, config->key);
214 MY_SETOPT_STR(curl, CURLOPT_SSH_PUBLIC_KEYFILE, config->pubkey);
216 /* SSH host key MD5 checking allows us to fail if we are not talking to who
217 we think we should */
218 MY_SETOPT_STR(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, config->hostpubmd5);
220 /* SSH host key SHA256 checking allows us to fail if we are not talking to
221 who we think we should */
222 MY_SETOPT_STR(curl, CURLOPT_SSH_HOST_PUBLIC_KEY_SHA256,
223 config->hostpubsha256);
225 if(config->ssh_compression)
226 my_setopt_long(curl, CURLOPT_SSH_COMPRESSION, 1);
228 if(!config->insecure_ok) {
229 char *known = config->knownhosts;
230 if(!known) {
231 char *found = findfile(".ssh/known_hosts", FALSE);
232 if(found) {
233 known = curlx_strdup(found);
234 curl_free(found);
235 if(!known)
236 return CURLE_OUT_OF_MEMORY;
237 }
238 else if(!config->hostpubmd5 && !config->hostpubsha256) {
239 /* couldn't find an existing one, instead set one that MIGHT work as
240 we don't verify the host using other means */
241 struct dynbuf k;
242 char *home = getenv("HOME");
243 curlx_dyn_init(&k, 256);
245 /* If the HOME environment variable is missing this renders a path
246 that is likely to not work but the HOME one also does not exist!
247 */
248 result = curlx_dyn_addf(&k,
249 "%s" DIR_CHAR ".ssh" DIR_CHAR "known_hosts",
250 home ? home : "");
251 if(result)
252 return result;
253 known = curlx_dyn_ptr(&k);
254 }
255 }
257 if(known) {
258 result = my_setopt_str(curl, CURLOPT_SSH_KNOWNHOSTS, known);
259 if(result) {
260 config->knownhosts = NULL;
261 curlx_free(known);
262 return result;
263 }
264 /* store it in global to avoid repeated checks */
265 config->knownhosts = known;
266 }
267 }
268 return CURLE_OK; /* ignore if SHA256 did not work */
271static long tlsversion(unsigned char mintls,
272 unsigned char maxtls)
274 long tlsver = 0;
275 if(!mintls && /* minimum is at default */
276 /* minimum is set to default, which we want to be 1.2 */
277 maxtls && (maxtls < 3)) {
278 /* max is set lower than 1.2 and minimum is default, change minimum to
279 the same as max */
280 mintls = maxtls;
281 }
282 switch(mintls) {
283 case 1:
284 tlsver = CURL_SSLVERSION_TLSv1_0;
285 break;
286 case 2:
287 tlsver = CURL_SSLVERSION_TLSv1_1;
288 break;
289 case 0: /* let default minimum be 1.2 */
290 case 3:
291 tlsver = CURL_SSLVERSION_TLSv1_2;
292 break;
293 case 4:
294 default: /* in case */
295 tlsver = CURL_SSLVERSION_TLSv1_3;
296 break;
297 }
298 switch(maxtls) {
299 case 0: /* not set, leave it */
300 break;
301 case 1:
302 tlsver |= CURL_SSLVERSION_MAX_TLSv1_0;
303 break;
304 case 2:
305 tlsver |= CURL_SSLVERSION_MAX_TLSv1_1;
306 break;
307 case 3:
308 tlsver |= CURL_SSLVERSION_MAX_TLSv1_2;
309 break;
310 case 4:
311 default: /* in case */
312 tlsver |= CURL_SSLVERSION_MAX_TLSv1_3;
313 break;
314 }
315 return tlsver;
318/* only called if libcurl supports TLS */
319static CURLcode ssl_ca_setopts(struct OperationConfig *config, CURL *curl)
321 CURLcode result = CURLE_OK;
323 if(config->cacert)
324 MY_SETOPT_STR(curl, CURLOPT_CAINFO, config->cacert);
325 if(config->proxy_cacert)
326 MY_SETOPT_STR(curl, CURLOPT_PROXY_CAINFO, config->proxy_cacert);
327 if(config->capath)
328 MY_SETOPT_STR(curl, CURLOPT_CAPATH, config->capath);
330 /* For the time being if --proxy-capath is not set then we use the
331 --capath value for it, if any. See #1257 */
332 if(config->proxy_capath || config->capath) {
333 MY_SETOPT_STR(curl, CURLOPT_PROXY_CAPATH,
334 (config->proxy_capath ? config->proxy_capath :
335 config->capath));
336 if((result == CURLE_NOT_BUILT_IN) || (result == CURLE_UNKNOWN_OPTION)) {
337 warnf("ignoring %s, not supported by libcurl with %s",
338 "setting the CA path for the proxy",
339 ssl_backend());
340 result = CURLE_OK;
341 }
342 }
343 if(result)
344 return result;
346#ifdef CURL_CA_EMBED
347 if(!config->cacert && !config->capath) {
348 struct curl_blob blob;
349 blob.data = CURL_UNCONST(curl_ca_embed);
350 blob.len = strlen((const char *)curl_ca_embed);
351 blob.flags = CURL_BLOB_NOCOPY;
352 notef("Using embedded CA bundle (%zu bytes)", blob.len);
353 result = curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob);
354 if((result == CURLE_NOT_BUILT_IN) || (result == CURLE_UNKNOWN_OPTION)) {
355 warnf("ignoring %s, not supported by libcurl with %s",
356 "embedded CA bundle", ssl_backend());
357 result = CURLE_OK;
358 }
359 }
360 if(!config->proxy_cacert && !config->proxy_capath) {
361 struct curl_blob blob;
362 blob.data = CURL_UNCONST(curl_ca_embed);
363 blob.len = strlen((const char *)curl_ca_embed);
364 blob.flags = CURL_BLOB_NOCOPY;
365 notef("Using embedded CA bundle, for proxies (%zu bytes)", blob.len);
366 result = curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO_BLOB, &blob);
367 if((result == CURLE_NOT_BUILT_IN) || (result == CURLE_UNKNOWN_OPTION)) {
368 warnf("ignoring %s, not supported by libcurl with %s",
369 "embedded CA bundle", ssl_backend());
370 result = CURLE_OK;
371 }
372 }
373#endif
374 return result;
377/* only called if libcurl supports TLS */
378static CURLcode ssl_setopts(struct OperationConfig *config, CURL *curl)
380 CURLcode result = CURLE_OK;
382 if(config->crlfile)
383 MY_SETOPT_STR(curl, CURLOPT_CRLFILE, config->crlfile);
384 if(config->proxy_crlfile)
385 MY_SETOPT_STR(curl, CURLOPT_PROXY_CRLFILE, config->proxy_crlfile);
386 else if(config->crlfile)
387 /* CURLOPT_PROXY_CRLFILE default is crlfile */
388 MY_SETOPT_STR(curl, CURLOPT_PROXY_CRLFILE, config->crlfile);
390 if(config->pinnedpubkey) {
391 MY_SETOPT_STR(curl, CURLOPT_PINNEDPUBLICKEY, config->pinnedpubkey);
392 if(result)
393 warnf("ignoring %s, not supported by libcurl with %s",
394 "--pinnedpubkey", ssl_backend());
395 }
396 if(config->proxy_pinnedpubkey) {
397 MY_SETOPT_STR(curl, CURLOPT_PROXY_PINNEDPUBLICKEY,
398 config->proxy_pinnedpubkey);
399 if(result)
400 warnf("ignoring %s, not supported by libcurl with %s",
401 "--proxy-pinnedpubkey", ssl_backend());
402 }
404 if(config->ssl_ec_curves)
405 MY_SETOPT_STR(curl, CURLOPT_SSL_EC_CURVES, config->ssl_ec_curves);
407 if(config->ssl_signature_algorithms)
408 MY_SETOPT_STR(curl, CURLOPT_SSL_SIGNATURE_ALGORITHMS,
409 config->ssl_signature_algorithms);
411 if(config->writeout)
412 my_setopt_long(curl, CURLOPT_CERTINFO, 1);
414 MY_SETOPT_STR(curl, CURLOPT_SSLCERT, config->cert);
415 MY_SETOPT_STR(curl, CURLOPT_PROXY_SSLCERT, config->proxy_cert);
416 MY_SETOPT_STR(curl, CURLOPT_SSLCERTTYPE, config->cert_type);
417 MY_SETOPT_STR(curl, CURLOPT_PROXY_SSLCERTTYPE, config->proxy_cert_type);
418 MY_SETOPT_STR(curl, CURLOPT_SSLKEY, config->key);
419 MY_SETOPT_STR(curl, CURLOPT_PROXY_SSLKEY, config->proxy_key);
420 MY_SETOPT_STR(curl, CURLOPT_SSLKEYTYPE, config->key_type);
421 MY_SETOPT_STR(curl, CURLOPT_PROXY_SSLKEYTYPE, config->proxy_key_type);
423 /* libcurl default is strict verifyhost -> 1L, verifypeer -> 1L. Set
424 these for every operation so --libcurl output does not retain
425 --insecure from a preceding --next operation. */
426 my_setopt_long_force(curl, CURLOPT_SSL_VERIFYPEER,
427 config->insecure_ok ? 0 : 1);
428 my_setopt_long_force(curl, CURLOPT_SSL_VERIFYHOST,
429 config->insecure_ok ? 0 : 1);
431 if(config->doh_insecure_ok) {
432 my_setopt_long(curl, CURLOPT_DOH_SSL_VERIFYPEER, 0);
433 my_setopt_long(curl, CURLOPT_DOH_SSL_VERIFYHOST, 0);
434 }
436 if(config->proxy_insecure_ok) {
437 my_setopt_long(curl, CURLOPT_PROXY_SSL_VERIFYPEER, 0);
438 my_setopt_long(curl, CURLOPT_PROXY_SSL_VERIFYHOST, 0);
439 }
441 if(config->verifystatus)
442 my_setopt_long(curl, CURLOPT_SSL_VERIFYSTATUS, 1);
444 if(config->doh_verifystatus)
445 my_setopt_long(curl, CURLOPT_DOH_SSL_VERIFYSTATUS, 1);
447 my_setopt_SSLVERSION(curl, CURLOPT_SSLVERSION,
448 tlsversion(config->ssl_version,
449 config->ssl_version_max));
450 if(config->proxy)
451 my_setopt_SSLVERSION(curl, CURLOPT_PROXY_SSLVERSION,
452 config->proxy_ssl_version);
454 {
455 long mask =
456 (config->ssl_allow_beast ? CURLSSLOPT_ALLOW_BEAST : 0) |
457 (config->ssl_allow_earlydata ? CURLSSLOPT_EARLYDATA : 0) |
458 (config->ssl_no_revoke ? CURLSSLOPT_NO_REVOKE : 0) |
459 (config->ssl_revoke_best_effort ? CURLSSLOPT_REVOKE_BEST_EFFORT : 0) |
460 (config->native_ca_store ? CURLSSLOPT_NATIVE_CA : 0) |
461 (config->ssl_auto_client_cert ? CURLSSLOPT_AUTO_CLIENT_CERT : 0);
463 if(mask)
464 my_setopt_bitmask(curl, CURLOPT_SSL_OPTIONS, mask);
465 }
467 {
468 long mask =
469 (config->proxy_ssl_allow_beast ? CURLSSLOPT_ALLOW_BEAST : 0) |
470 (config->proxy_ssl_auto_client_cert ? CURLSSLOPT_AUTO_CLIENT_CERT : 0) |
471 (config->proxy_native_ca_store ? CURLSSLOPT_NATIVE_CA : 0);
473 if(mask)
474 my_setopt_bitmask(curl, CURLOPT_PROXY_SSL_OPTIONS, mask);
475 }
477 if(config->cipher_list) {
478 MY_SETOPT_STR(curl, CURLOPT_SSL_CIPHER_LIST, config->cipher_list);
479 if(result)
480 warnf("ignoring %s, not supported by libcurl with %s",
481 "--ciphers", ssl_backend());
482 }
483 if(config->proxy_cipher_list) {
484 MY_SETOPT_STR(curl, CURLOPT_PROXY_SSL_CIPHER_LIST,
485 config->proxy_cipher_list);
486 if(result)
487 warnf("ignoring %s, not supported by libcurl with %s",
488 "--proxy-ciphers", ssl_backend());
489 }
490 if(config->cipher13_list) {
491 MY_SETOPT_STR(curl, CURLOPT_TLS13_CIPHERS, config->cipher13_list);
492 if(result)
493 warnf("ignoring %s, not supported by libcurl with %s",
494 "--tls13-ciphers", ssl_backend());
495 }
496 if(config->proxy_cipher13_list) {
497 MY_SETOPT_STR(curl, CURLOPT_PROXY_TLS13_CIPHERS,
498 config->proxy_cipher13_list);
499 if(result)
500 warnf("ignoring %s, not supported by libcurl with %s",
501 "--proxy-tls13-ciphers", ssl_backend());
502 }
504 /* curl 7.16.0 */
505 if(config->disable_sessionid)
506 /* disable it */
507 my_setopt_long(curl, CURLOPT_SSL_SESSIONID_CACHE, 0);
509 if(feature_ech) {
510 /* only if enabled in libcurl */
511 if(config->ech_public) /* only if set (optional) */
512 MY_SETOPT_STR(curl, CURLOPT_ECH, config->ech_public);
513 if(config->ech_config) /* only if set (optional) */
514 MY_SETOPT_STR(curl, CURLOPT_ECH, config->ech_config);
515 if(config->ech) /* only if set (optional) */
516 MY_SETOPT_STR(curl, CURLOPT_ECH, config->ech);
517 }
519 if(config->engine)
520 MY_SETOPT_STR(curl, CURLOPT_SSLENGINE, config->engine);
522 if(config->ftp_ssl_reqd)
523 my_setopt_enum(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);
525 else if(config->ftp_ssl)
526 my_setopt_enum(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
528 else if(config->ftp_ssl_control)
529 my_setopt_enum(curl, CURLOPT_USE_SSL, CURLUSESSL_CONTROL);
531 if(config->noalpn)
532 my_setopt_long(curl, CURLOPT_SSL_ENABLE_ALPN, 0);
534 return CURLE_OK;
537static CURLcode cookie_setopts(struct OperationConfig *config, CURL *curl)
539 CURLcode result = CURLE_OK;
540 if(config->cookies) {
541 struct dynbuf cookies;
542 struct curl_slist *cl;
544 /* cap the size of the generated cookie header to avoid servers from going
545 sour on us */
546#define MAX_REQUEST_COOKIE 8200
547 curlx_dyn_init(&cookies, MAX_REQUEST_COOKIE);
548 for(cl = config->cookies; cl; cl = cl->next) {
549 if(cl == config->cookies)
550 result = curlx_dyn_add(&cookies, cl->data);
551 else
552 result = curlx_dyn_addf(&cookies, ";%s%s",
553 ISBLANK(cl->data[0]) ? "" : " ", cl->data);
554 if(result) {
555 warnf("skipped provided cookie, the cookie header "
556 "would go over %d bytes", MAX_REQUEST_COOKIE);
557 return result;
558 }
559 }
561 result = my_setopt_str(curl, CURLOPT_COOKIE, curlx_dyn_ptr(&cookies));
562 curlx_dyn_free(&cookies);
563 if(result)
564 return result;
565 }
567 if(config->cookiefiles) {
568 struct curl_slist *cfl;
570 for(cfl = config->cookiefiles; cfl; cfl = cfl->next)
571 MY_SETOPT_STR(curl, CURLOPT_COOKIEFILE, cfl->data);
572 }
574 if(config->cookiejar)
575 MY_SETOPT_STR(curl, CURLOPT_COOKIEJAR, config->cookiejar);
577 my_setopt_long(curl, CURLOPT_COOKIESESSION, config->cookiesession);
579 return result;
582/* only --httpsig-* options */
583#ifndef CURL_DISABLE_HTTPSIG
584static CURLcode httpsig_setopts(struct OperationConfig *config, CURL *curl)
586 CURLcode result = CURLE_OK;
587 /* HTTP Message Signatures are enabled when any of the --httpsig-* options
588 is given. --httpsig-key and --httpsig-keyid are then required, while
589 --httpsig-algo is optional and defaults to ed25519. */
590 if(config->httpsig_algorithm || config->httpsig_key ||
591 config->httpsig_keyid || config->httpsig_headers) {
592 long httpsig_alg = CURLHTTPSIG_NONE;
594 if(!config->httpsig_key) {
595 errorf("--httpsig-key is required");
596 return CURLE_FAILED_INIT;
597 }
598 if(!config->httpsig_keyid) {
599 errorf("--httpsig-keyid is required");
600 return CURLE_FAILED_INIT;
601 }
603 if(!config->httpsig_algorithm ||
604 curl_strequal(config->httpsig_algorithm, "ed25519"))
605 httpsig_alg = CURLHTTPSIG_ED25519;
606 else if(curl_strequal(config->httpsig_algorithm, "hmac-sha256"))
607 httpsig_alg = CURLHTTPSIG_HMAC_SHA256;
608 else {
609 errorf("--httpsig-algo: unsupported algorithm '%s'",
610 config->httpsig_algorithm);
611 return CURLE_FAILED_INIT;
612 }
613 my_setopt_long(curl, CURLOPT_HTTPSIG_ALGORITHM, httpsig_alg);
614 MY_SETOPT_STR(curl, CURLOPT_HTTPSIG_HEADERS, config->httpsig_headers);
615 MY_SETOPT_STR(curl, CURLOPT_HTTPSIG_KEYID, config->httpsig_keyid);
617 if(config->httpsig_key[0] == '@') {
618 FILE *keyf = curlx_fopen(&config->httpsig_key[1], FOPEN_READTEXT);
619 if(keyf) {
620 char *hexdata = NULL;
621 ParameterError pe = file2string(&hexdata, keyf);
623 curlx_fclose(keyf);
624 if(pe == PARAM_NO_MEM) {
625 curlx_safefree(hexdata);
626 return CURLE_OUT_OF_MEMORY;
627 }
628 if(pe == PARAM_READ_ERROR) {
629 curlx_safefree(hexdata);
630 errorf("httpsig: cannot read key file '%s'",
631 &config->httpsig_key[1]);
632 return CURLE_READ_ERROR;
633 }
634 if(!hexdata || !*hexdata) {
635 curlx_safefree(hexdata);
636 errorf("httpsig: key file '%s' is empty", &config->httpsig_key[1]);
637 return CURLE_BAD_FUNCTION_ARGUMENT;
638 }
639 /* can't use the MY_SETOPT_STR() macro here since it returns on error
640 and we must free the hexdata */
641 result = my_setopt_str(curl, CURLOPT_HTTPSIG_KEY, hexdata);
642 curlx_safefree(hexdata);
643 if(setopt_bad(result))
644 return result;
645 }
646 else {
647 errorf("httpsig: cannot open key file '%s'", &config->httpsig_key[1]);
648 return CURLE_READ_ERROR;
649 }
650 }
651 else {
652 if(!config->httpsig_key[0]) {
653 errorf("httpsig: key is empty");
654 return CURLE_BAD_FUNCTION_ARGUMENT;
655 }
656 MY_SETOPT_STR(curl, CURLOPT_HTTPSIG_KEY, config->httpsig_key);
657 }
658 }
659 return CURLE_OK;
661#else
662#define httpsig_setopts(x,y) CURLE_OK
663#endif
665/* only for HTTP transfers */
666static CURLcode http_setopts(struct OperationConfig *config, CURL *curl,
667 const char *use_proto)
669 CURLcode result = CURLE_OK;
670 long postRedir = 0;
672 if(config->hsts)
673 MY_SETOPT_STR(curl, CURLOPT_HSTS, config->hsts);
675 if(use_proto != proto_http && use_proto != proto_https)
676 return CURLE_OK;
678 my_setopt_long(curl, CURLOPT_FOLLOWLOCATION, config->followlocation);
679 my_setopt_long(curl, CURLOPT_UNRESTRICTED_AUTH, config->unrestricted_auth);
680#ifndef CURL_DISABLE_AWS
681 MY_SETOPT_STR(curl, CURLOPT_AWS_SIGV4, config->aws_sigv4);
682#endif
683 result = httpsig_setopts(config, curl);
684 if(result)
685 return result;
686 my_setopt_long(curl, CURLOPT_AUTOREFERER, config->autoreferer);
688 if(config->proxyheaders) {
689 my_setopt_slist(curl, CURLOPT_PROXYHEADER, config->proxyheaders);
690 }
692 my_setopt_long(curl, CURLOPT_MAXREDIRS, config->maxredirs);
694 if(config->httpversion)
695 my_setopt_enum(curl, CURLOPT_HTTP_VERSION, config->httpversion);
697 if(config->post301)
698 postRedir |= CURL_REDIR_POST_301;
699 if(config->post302)
700 postRedir |= CURL_REDIR_POST_302;
701 if(config->post303)
702 postRedir |= CURL_REDIR_POST_303;
703 my_setopt_long(curl, CURLOPT_POSTREDIR, postRedir);
705 if(config->encoding)
706 MY_SETOPT_STR(curl, CURLOPT_ACCEPT_ENCODING, "");
708 if(config->tr_encoding)
709 my_setopt_long(curl, CURLOPT_TRANSFER_ENCODING, 1);
711 my_setopt_long(curl, CURLOPT_HTTP09_ALLOWED, config->http09_allowed);
713 if(config->altsvc)
714 MY_SETOPT_STR(curl, CURLOPT_ALTSVC, config->altsvc);
716 if(config->expect100timeout_ms > 0)
717 my_setopt_long(curl, CURLOPT_EXPECT_100_TIMEOUT_MS,
718 config->expect100timeout_ms);
720 if(!result)
721 result = cookie_setopts(config, curl);
722 if(result)
723 return result;
724 /* Enable header separation when using a proxy with HTTPS or proxytunnel
725 * to prevent --header content from leaking into CONNECT requests */
726 if((config->proxy || config->proxyheaders) &&
727 (use_proto == proto_https || config->proxytunnel))
728 my_setopt_long(curl, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE);
729 return result;
732static void tcp_setopts(struct OperationConfig *config, CURL *curl)
734 if(!config->tcp_nodelay)
735 my_setopt_long(curl, CURLOPT_TCP_NODELAY, 0);
737 if(config->tcp_fastopen)
738 my_setopt_long(curl, CURLOPT_TCP_FASTOPEN, 1);
740 if(config->mptcp)
741 my_setopt_ptr(curl, CURLOPT_OPENSOCKETFUNCTION, tool_socket_open_mptcp_cb);
743 /* curl 7.17.1 */
744 if(!config->nokeepalive) {
745 my_setopt_long(curl, CURLOPT_TCP_KEEPALIVE, 1);
746 if(config->alivetime) {
747 my_setopt_long(curl, CURLOPT_TCP_KEEPIDLE, config->alivetime);
748 my_setopt_long(curl, CURLOPT_TCP_KEEPINTVL, config->alivetime);
749 }
750 if(config->alivecnt)
751 my_setopt_long(curl, CURLOPT_TCP_KEEPCNT, config->alivecnt);
752 }
753 else
754 my_setopt_long(curl, CURLOPT_TCP_KEEPALIVE, 0);
757static CURLcode ftp_setopts(struct OperationConfig *config, CURL *curl,
758 const char *use_proto)
760 CURLcode result;
762 if(use_proto != proto_ftp && use_proto != proto_ftps)
763 return CURLE_OK;
765 MY_SETOPT_STR(curl, CURLOPT_FTPPORT, config->ftpport);
767 if(config->disable_epsv)
768 /* disable it */
769 my_setopt_long(curl, CURLOPT_FTP_USE_EPSV, 0);
771 if(config->disable_eprt)
772 /* disable it */
773 my_setopt_long(curl, CURLOPT_FTP_USE_EPRT, 0);
775 if(config->ftp_ssl_ccc)
776 my_setopt_enum(curl, CURLOPT_FTP_SSL_CCC, config->ftp_ssl_ccc_mode);
778 MY_SETOPT_STR(curl, CURLOPT_FTP_ACCOUNT, config->ftp_account);
779 my_setopt_long(curl, CURLOPT_FTP_SKIP_PASV_IP, config->ftp_skip_ip);
780 my_setopt_long(curl, CURLOPT_FTP_FILEMETHOD, config->ftp_filemethod);
781 MY_SETOPT_STR(curl, CURLOPT_FTP_ALTERNATIVE_TO_USER,
782 config->ftp_alternative_to_user);
784 if(config->ftp_pret)
785 my_setopt_long(curl, CURLOPT_FTP_USE_PRET, 1);
787 return result;
790static void gen_trace_setopts(struct OperationConfig *config, CURL *curl)
792 if(global->tracetype != TRACE_NONE) {
793 my_setopt_ptr(curl, CURLOPT_DEBUGFUNCTION, tool_debug_cb);
794 my_setopt_ptr(curl, CURLOPT_DEBUGDATA, config);
795 my_setopt_long(curl, CURLOPT_VERBOSE, 1L);
796 }
799static void gen_cb_setopts(struct OperationConfig *config,
800 struct per_transfer *per,
801 CURL *curl)
803 (void)config; /* when --libcurl is disabled */
805 /* where to store */
806 my_setopt_ptr(curl, CURLOPT_WRITEDATA, per);
807 my_setopt_ptr(curl, CURLOPT_INTERLEAVEDATA, per);
809 /* what call to write */
810 my_setopt_ptr(curl, CURLOPT_WRITEFUNCTION, tool_write_cb);
812 /* what to read */
813 my_setopt_ptr(curl, CURLOPT_READDATA, per);
814 my_setopt_ptr(curl, CURLOPT_READFUNCTION, tool_read_cb);
816 /* in 7.18.0, the CURLOPT_SEEKFUNCTION/DATA pair is taking over what
817 CURLOPT_IOCTLFUNCTION/DATA pair previously provided for seeking */
818 my_setopt_ptr(curl, CURLOPT_SEEKDATA, per);
819 my_setopt_ptr(curl, CURLOPT_SEEKFUNCTION, tool_seek_cb);
821 if((global->progressmode == CURL_PROGRESS_BAR) &&
822 !global->noprogress && !global->silent) {
823 /* we want the alternative style, then we have to implement it
824 ourselves! */
825 my_setopt_ptr(curl, CURLOPT_XFERINFOFUNCTION, tool_progress_cb);
826 my_setopt_ptr(curl, CURLOPT_XFERINFODATA, per);
827 }
828 else if(per->uploadfile && !strcmp(per->uploadfile, ".")) {
829 /* when reading from stdin in non-blocking mode, we use the progress
830 function to unpause a busy read */
831 my_setopt_long(curl, CURLOPT_NOPROGRESS, 0);
832 my_setopt_ptr(curl, CURLOPT_XFERINFOFUNCTION, tool_readbusy_cb);
833 my_setopt_ptr(curl, CURLOPT_XFERINFODATA, per);
834 }
836 my_setopt_ptr(curl, CURLOPT_HEADERFUNCTION, tool_header_cb);
837 my_setopt_ptr(curl, CURLOPT_HEADERDATA, per);
840static CURLcode proxy_setopts(struct OperationConfig *config, CURL *curl)
842 CURLcode result;
843 if(config->proxy) {
844 result = my_setopt_str(curl, CURLOPT_PROXY, config->proxy);
845 if(result) {
846 errorf("proxy support is disabled in this libcurl");
847 config->synthetic_error = TRUE;
848 return CURLE_NOT_BUILT_IN;
849 }
850 }
852 if(config->proxy)
853 my_setopt_enum(curl, CURLOPT_PROXYTYPE, config->proxyver);
855 MY_SETOPT_STR(curl, CURLOPT_PROXYUSERPWD, config->proxyuserpwd);
856 my_setopt_long(curl, CURLOPT_HTTPPROXYTUNNEL, config->proxytunnel);
857 if(config->preproxy)
858 MY_SETOPT_STR(curl, CURLOPT_PRE_PROXY, config->preproxy);
860 if(config->proxyanyauth)
861 my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
862 else if(config->proxynegotiate)
863 my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_GSSNEGOTIATE);
864 else if(config->proxyntlm)
865 my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_NTLM);
866 else if(config->proxydigest)
867 my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
868 else if(config->proxybasic)
869 my_setopt_bitmask(curl, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
871 MY_SETOPT_STR(curl, CURLOPT_NOPROXY, config->noproxy);
872 my_setopt_long(curl, CURLOPT_SUPPRESS_CONNECT_HEADERS,
873 config->suppress_connect_headers);
875 if(config->proxy_service_name)
876 MY_SETOPT_STR(curl, CURLOPT_PROXY_SERVICE_NAME,
877 config->proxy_service_name);
879 if(config->haproxy_protocol)
880 my_setopt_long(curl, CURLOPT_HAPROXYPROTOCOL, 1);
882 if(config->haproxy_clientip)
883 MY_SETOPT_STR(curl, CURLOPT_HAPROXY_CLIENT_IP, config->haproxy_clientip);
885 MY_SETOPT_STR(curl, CURLOPT_PROXY_KEYPASSWD, config->proxy_key_passwd);
887 return result;
890static CURLcode check_post_resume(struct OperationConfig *config)
892 if(config->use_resume &&
893 (config->resume_from || config->resume_from_current)) {
894 errorf("(%d) HTTP upload cannot be resumed",
895 CURLE_BAD_FUNCTION_ARGUMENT);
896 config->synthetic_error = TRUE;
897 return CURLE_BAD_FUNCTION_ARGUMENT;
898 }
899 return CURLE_OK;
902static CURLcode setopt_post(struct OperationConfig *config, CURL *curl)
904 CURLcode result = CURLE_OK;
905 switch(config->httpreq) {
906 case TOOL_HTTPREQ_SIMPLEPOST:
907 result = check_post_resume(config);
908 if(!result) {
909 MY_SETOPT_STR(curl, CURLOPT_POSTFIELDS,
910 curlx_dyn_ptr(&config->postdata));
911 my_setopt_offt(curl, CURLOPT_POSTFIELDSIZE_LARGE,
912 curlx_dyn_len(&config->postdata));
913 }
914 break;
915 case TOOL_HTTPREQ_MIMEPOST:
916 /* free previous remainders */
917 curl_mime_free(config->mimepost);
918 config->mimepost = NULL;
919 result = check_post_resume(config);
920 if(!result) {
921 result = tool2curlmime(curl, config->mimeroot, &config->mimepost);
922 if(!result)
923 result = my_setopt_mimepost(curl, CURLOPT_MIMEPOST, config->mimepost);
924 }
925 break;
926 default:
927 break;
928 }
929 return result;
932static void buffersize(struct OperationConfig *config, CURL *curl)
934#ifdef DEBUGBUILD
935 char *env = getenv("CURL_BUFFERSIZE");
936 if(env) {
937 curl_off_t num;
938 const char *p = env;
939 if(!curlx_str_number(&p, &num, LONG_MAX))
940 my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)num);
941 return;
942 }
943#endif
944 if(config->recvpersecond && (config->recvpersecond < BUFFER_SIZE))
945 /* use a smaller sized buffer for better sleeps */
946 my_setopt_long(curl, CURLOPT_BUFFERSIZE, (long)config->recvpersecond);
947 else
948 my_setopt_long(curl, CURLOPT_BUFFERSIZE, BUFFER_SIZE);
951static CURLcode credentials_and_headers_setopts(struct OperationConfig *config,
952 CURL *curl)
954 CURLcode result = CURLE_OK;
956 MY_SETOPT_STR(curl, CURLOPT_XOAUTH2_BEARER, config->oauth_bearer);
957 if(config->netrc_opt)
958 my_setopt_enum(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL);
959 else if(config->netrc || config->netrc_file)
960 my_setopt_enum(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
961 else
962 my_setopt_enum(curl, CURLOPT_NETRC, CURL_NETRC_IGNORED);
964 MY_SETOPT_STR(curl, CURLOPT_NETRC_FILE, config->netrc_file);
965 MY_SETOPT_STR(curl, CURLOPT_LOGIN_OPTIONS, config->login_options);
966 MY_SETOPT_STR(curl, CURLOPT_USERPWD, config->userpwd);
968 if(config->authtype)
969 my_setopt_bitmask(curl, CURLOPT_HTTPAUTH, config->authtype);
971 my_setopt_slist(curl, CURLOPT_HTTPHEADER, config->headers);
973 if(proto_http || proto_rtsp) {
974 MY_SETOPT_STR(curl, CURLOPT_REFERER, config->referer);
975 MY_SETOPT_STR(curl, CURLOPT_USERAGENT, config->useragent ?
976 config->useragent : CURL_NAME "/" CURL_VERSION);
977 }
979 MY_SETOPT_STR(curl, CURLOPT_KEYPASSWD, config->key_passwd);
980 return result;
983static CURLcode transfer_setopts(struct OperationConfig *config,
984 struct per_transfer *per,
985 CURL *curl)
987 CURLcode result = CURLE_OK;
989 my_setopt_long(curl, CURLOPT_NOBODY, config->no_body);
990 my_setopt_long(curl, CURLOPT_FAILONERROR, config->fail == FAIL_WO_BODY);
991 MY_SETOPT_STR(curl, CURLOPT_REQUEST_TARGET, config->request_target);
992 my_setopt_long(curl, CURLOPT_UPLOAD, !!per->uploadfile);
993 my_setopt_long(curl, CURLOPT_DIRLISTONLY, config->dirlistonly);
994 my_setopt_long(curl, CURLOPT_APPEND, config->ftp_append);
996 my_setopt_long(curl, CURLOPT_TRANSFERTEXT, config->use_ascii);
997 MY_SETOPT_STR(curl, CURLOPT_RANGE, config->range);
998 my_setopt_ptr(curl, CURLOPT_ERRORBUFFER, per->errorbuffer);
999 my_setopt_long(curl, CURLOPT_TIMEOUT_MS, config->timeout_ms);
1001 result = setopt_post(config, curl);
1002 if(result)
1003 return result;
1005 if(config->mime_options)
1006 my_setopt_long(curl, CURLOPT_MIME_OPTIONS, config->mime_options);
1008 my_setopt_long(curl, CURLOPT_LOW_SPEED_LIMIT, config->low_speed_limit);
1009 my_setopt_long(curl, CURLOPT_LOW_SPEED_TIME, config->low_speed_time);
1010 my_setopt_offt(curl, CURLOPT_MAX_SEND_SPEED_LARGE, config->sendpersecond);
1011 my_setopt_offt(curl, CURLOPT_MAX_RECV_SPEED_LARGE, config->recvpersecond);
1013 if(config->use_resume)
1014 my_setopt_offt(curl, CURLOPT_RESUME_FROM_LARGE, config->resume_from);
1015 else
1016 my_setopt_offt(curl, CURLOPT_RESUME_FROM_LARGE, 0);
1018 if(config->path_as_is)
1019 my_setopt_long(curl, CURLOPT_PATH_AS_IS, 1);
1021 if(config->no_body || config->remote_time)
1022 my_setopt_long(curl, CURLOPT_FILETIME, 1);
1024 my_setopt_long(curl, CURLOPT_CRLF, config->crlf);
1025 my_setopt_slist(curl, CURLOPT_QUOTE, config->quote);
1026 my_setopt_slist(curl, CURLOPT_POSTQUOTE, config->postquote);
1027 my_setopt_slist(curl, CURLOPT_PREQUOTE, config->prequote);
1029 my_setopt_enum(curl, CURLOPT_TIMECONDITION, config->timecond);
1030 my_setopt_offt(curl, CURLOPT_TIMEVALUE_LARGE, config->condtime);
1031 MY_SETOPT_STR(curl, CURLOPT_CUSTOMREQUEST, config->customrequest);
1032 customrequest_helper(config->httpreq, config->customrequest);
1034 return result;
1037static CURLcode protocol_setopts(struct OperationConfig *config,
1038 struct per_transfer *per,
1039 CURL *curl,
1040 const char *use_proto)
1042 CURLcode result = CURLE_OK;
1043#ifndef DEBUGBUILD
1044 (void)per;
1045#endif
1046 result = http_setopts(config, curl, use_proto);
1047 if(!result)
1048 result = ftp_setopts(config, curl, use_proto);
1049 if(result)
1050 return result;
1052 result = ssh_setopts(config, curl);
1053 if(setopt_bad(result))
1054 return result;
1056 if(feature_ssl) {
1057 result = ssl_ca_setopts(config, curl);
1058 if(!result)
1059 result = ssl_setopts(config, curl);
1060 if(setopt_bad(result))
1061 return result;
1062#ifdef DEBUGBUILD
1063 if(!per->urlnum) {
1064 char *env = getenv("CURL_DBG_NO_USE_SSL_ON_FIRST");
1065 if(env)
1066 my_setopt_enum(curl, CURLOPT_USE_SSL, CURLUSESSL_NONE);
1068#endif
1071 return result;
1074static CURLcode dns_and_network_setopts(struct OperationConfig *config,
1075 struct per_transfer *per,
1076 CURL *curl)
1078 CURLcode result = CURLE_OK;
1080 MY_SETOPT_STR(curl, CURLOPT_INTERFACE, config->iface);
1081 progressbarinit(&per->progressbar, config);
1082 MY_SETOPT_STR(curl, CURLOPT_DNS_SERVERS, config->dns_servers);
1083 MY_SETOPT_STR(curl, CURLOPT_DNS_INTERFACE, config->dns_interface);
1084 MY_SETOPT_STR(curl, CURLOPT_DNS_LOCAL_IP4, config->dns_ipv4_addr);
1085 MY_SETOPT_STR(curl, CURLOPT_DNS_LOCAL_IP6, config->dns_ipv6_addr);
1086 my_setopt_slist(curl, CURLOPT_TELNETOPTIONS, config->telnet_options);
1087 my_setopt_long(curl, CURLOPT_CONNECTTIMEOUT_MS, config->connecttimeout_ms);
1088 MY_SETOPT_STR(curl, CURLOPT_DOH_URL, config->doh_url);
1089 my_setopt_long(curl, CURLOPT_FTP_CREATE_MISSING_DIRS,
1090 (config->ftp_create_dirs ?
1091 CURLFTP_CREATE_DIR_RETRY : CURLFTP_CREATE_DIR_NONE));
1092 my_setopt_offt(curl, CURLOPT_MAXFILESIZE_LARGE, config->max_filesize);
1093 my_setopt_long(curl, CURLOPT_IPRESOLVE, config->ip_version);
1094 if(config->socks5_gssapi_nec)
1095 my_setopt_long(curl, CURLOPT_SOCKS5_GSSAPI_NEC, 1);
1096 if(config->socks5_auth)
1097 my_setopt_bitmask(curl, CURLOPT_SOCKS5_AUTH, config->socks5_auth);
1098 MY_SETOPT_STR(curl, CURLOPT_SERVICE_NAME, config->service_name);
1099 my_setopt_long(curl, CURLOPT_IGNORE_CONTENT_LENGTH, config->ignorecl);
1101 if(config->localport) {
1102 my_setopt_long(curl, CURLOPT_LOCALPORT, config->localport);
1103 my_setopt_long(curl, CURLOPT_LOCALPORTRANGE, config->localportrange);
1106 if(config->raw) {
1107 my_setopt_long(curl, CURLOPT_HTTP_CONTENT_DECODING, 0);
1108 my_setopt_long(curl, CURLOPT_HTTP_TRANSFER_DECODING, 0);
1111 tcp_setopts(config, curl);
1113 if(config->tftp_blksize && proto_tftp)
1114 my_setopt_long(curl, CURLOPT_TFTP_BLKSIZE, config->tftp_blksize);
1116 return result;
1119static CURLcode mail_and_sasl_setopts(struct OperationConfig *config,
1120 CURL *curl)
1122 CURLcode result = CURLE_OK;
1124 MY_SETOPT_STR(curl, CURLOPT_MAIL_FROM, config->mail_from);
1125 my_setopt_slist(curl, CURLOPT_MAIL_RCPT, config->mail_rcpt);
1126 my_setopt_long(curl, CURLOPT_MAIL_RCPT_ALLOWFAILS,
1127 config->mail_rcpt_allowfails);
1128 MY_SETOPT_STR(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
1129 MY_SETOPT_STR(curl, CURLOPT_SASL_AUTHZID, config->sasl_authzid);
1130 my_setopt_long(curl, CURLOPT_SASL_IR, config->sasl_ir);
1132 if(config->create_file_mode)
1133 my_setopt_long(curl, CURLOPT_NEW_FILE_PERMS, config->create_file_mode);
1135 return result;
1138static CURLcode misc_setopts(struct OperationConfig *config, CURL *curl)
1140 CURLcode result = CURLE_OK;
1142 my_setopt_ptr(curl, CURLOPT_STDERR, tool_stderr);
1143 if(config->resolve)
1144 my_setopt_slist(curl, CURLOPT_RESOLVE, config->resolve);
1145 if(config->connect_to)
1146 my_setopt_slist(curl, CURLOPT_CONNECT_TO, config->connect_to);
1148 if(config->gssapi_delegation)
1149 my_setopt_long(curl, CURLOPT_GSSAPI_DELEGATION, config->gssapi_delegation);
1151 if(config->proto_present)
1152 MY_SETOPT_STR(curl, CURLOPT_PROTOCOLS_STR, config->proto_str);
1153 if(config->proto_redir_present)
1154 MY_SETOPT_STR(curl, CURLOPT_REDIR_PROTOCOLS_STR, config->proto_redir_str);
1156 if(config->gssapi_delegation)
1157 my_setopt_long(curl, CURLOPT_GSSAPI_DELEGATION, config->gssapi_delegation);
1159 MY_SETOPT_STR(curl, CURLOPT_MAIL_AUTH, config->mail_auth);
1160 MY_SETOPT_STR(curl, CURLOPT_SASL_AUTHZID, config->sasl_authzid);
1161 my_setopt_long(curl, CURLOPT_SASL_IR, config->sasl_ir);
1163 if(config->unix_socket_path) {
1164 if(config->abstract_unix_socket)
1165 MY_SETOPT_STR(curl, CURLOPT_ABSTRACT_UNIX_SOCKET,
1166 config->unix_socket_path);
1167 else
1168 MY_SETOPT_STR(curl, CURLOPT_UNIX_SOCKET_PATH,
1169 config->unix_socket_path);
1172 MY_SETOPT_STR(curl, CURLOPT_DEFAULT_PROTOCOL, config->proto_default);
1173 my_setopt_long(curl, CURLOPT_TFTP_NO_OPTIONS,
1174 config->tftp_no_options && proto_tftp);
1176 if(config->happy_eyeballs_timeout_ms != CURL_HET_DEFAULT)
1177 my_setopt_long(curl, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
1178 config->happy_eyeballs_timeout_ms);
1180 my_setopt_long(curl, CURLOPT_DISALLOW_USERNAME_IN_URL,
1181 config->disallow_username_in_url);
1183 if(config->ip_tos > 0 || config->vlan_priority > 0) {
1184#if defined(IP_TOS) || defined(IPV6_TCLASS) || defined(SO_PRIORITY)
1185 my_setopt_ptr(curl, CURLOPT_SOCKOPTFUNCTION, sockopt_callback);
1186 my_setopt_ptr(curl, CURLOPT_SOCKOPTDATA, config);
1187#else
1188 if(config->ip_tos > 0) {
1189 errorf("Type of service is not supported in this build.");
1190 result = CURLE_NOT_BUILT_IN;
1192 if(config->vlan_priority > 0) {
1193 errorf("VLAN priority is not supported in this build.");
1194 result = CURLE_NOT_BUILT_IN;
1196#endif
1198 if(!result)
1199 my_setopt_long(curl, CURLOPT_UPLOAD_FLAGS, config->upload_flags);
1201 return result;
1204CURLcode config2setopts(struct OperationConfig *config,
1205 struct per_transfer *per,
1206 CURL *curl,
1207 CURLSH *share)
1209 const char *use_proto;
1210 CURLcode result = url_proto_and_rewrite(&per->url, config, &use_proto);
1212 /* Avoid having this setopt added to the --libcurl source output. */
1213 if(!result)
1214 result = curl_easy_setopt(curl, CURLOPT_SHARE, share);
1215 if(result)
1216 return result;
1218#ifdef DEBUGBUILD
1219 if(getenv("CURL_QUICK_EXIT"))
1220#endif
1222 /* QUICK_EXIT allows for running threads to be detached and not
1223 * joined. Preferably in non-debug runs. */
1224 result = curl_easy_setopt(curl, CURLOPT_QUICK_EXIT, 1L);
1225 if(result)
1226 return result;
1229 gen_trace_setopts(config, curl);
1231 buffersize(config, curl);
1233 MY_SETOPT_STR(curl, CURLOPT_URL, per->url);
1234 my_setopt_long(curl, CURLOPT_NOPROGRESS,
1235 global->noprogress || global->silent);
1236 /* call after the line above. It may override CURLOPT_NOPROGRESS */
1237 gen_cb_setopts(config, per, curl);
1239 result = proxy_setopts(config, curl);
1240 if(setopt_bad(result) || config->synthetic_error)
1241 return result;
1243 result = credentials_and_headers_setopts(config, curl);
1244 if(!setopt_bad(result))
1245 result = transfer_setopts(config, per, curl);
1246 if(!setopt_bad(result))
1247 result = protocol_setopts(config, per, curl, use_proto);
1248 if(!setopt_bad(result))
1249 result = dns_and_network_setopts(config, per, curl);
1250 if(!setopt_bad(result))
1251 result = mail_and_sasl_setopts(config, curl);
1252 if(!setopt_bad(result))
1253 result = misc_setopts(config, curl);
1255 if(!result && config->synthetic_error)
1256 result = CURLE_FAILED_INIT;
1258 return result;
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 ms
discover200152 B2 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=30
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
fetch20011 KiB · hit30 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=11445
git.response.cache=HIT
git.response.duration_ms=30
git.fetch.wants=a92dcf3c3c6c0c3c3cb8839dc367212abae598ae
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=11445
git.pkt.payload.max=11424
git.sideband.band1.bytes=11423
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
a5e2dbe39c68c125
Request
9a38c41e…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format