Artifactspublic-v0

curl

master
ply4 git calls55 ms299 KiB3 cachedprotocol v2
1480 lines39 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_SYS_IOCTL_H
39#include <sys/ioctl.h>
40#endif
42#ifdef HAVE_SYS_PARAM_H
43#include <sys/param.h>
44#endif
46#include "urldata.h"
47#include "api.h"
48#include "transfer.h"
49#include "vdns/hostip.h"
50#include "vtls/vtls.h"
51#include "vtls/vtls_scache.h"
52#include "vquic/vquic.h"
53#include "url.h"
54#include "getinfo.h"
55#include "curlx/strdup.h"
56#include "easyif.h"
57#include "multiif.h"
58#include "multi_ev.h"
59#include "select.h"
60#include "cfilters.h"
61#include "sendf.h"
62#include "curl_trc.h"
63#include "connect.h" /* for Curl_getconnectinfo */
64#include "slist.h"
65#include "mime.h"
66#include "amigaos.h"
67#include "macos.h"
68#include "curlx/wait.h"
69#include "sigpipe.h"
70#include "vssh/ssh.h"
71#include "setopt.h"
72#include "http_digest.h"
73#include "curlx/dynbuf.h"
74#include "bufref.h"
75#include "altsvc.h"
76#include "hsts.h"
77#include "curl_sspi.h" /* Curl_sspi_global_init()/Curl_sspi_global_cleanup() */
78#include "curlx/timeval.h" /* for curlx_now_init() */
79#include "curlx/version_win32.h" /* for curlx_verify_windows_init() */
81#include "easy_lock.h"
83/* true globals -- for curl_global_init() and curl_global_cleanup() */
84static unsigned int initialized;
85#ifdef USE_WINSOCK
86static bool winsock_initialized;
87#endif
89#ifdef GLOBAL_INIT_IS_THREADSAFE
91static curl_simple_lock s_lock = CURL_SIMPLE_LOCK_INIT;
92#define global_init_lock() curl_simple_lock_lock(&s_lock)
93#define global_init_unlock() curl_simple_lock_unlock(&s_lock)
95#else
97#define global_init_lock()
98#define global_init_unlock()
100#endif
102#if defined(_MSC_VER) && defined(_DLL)
103# pragma warning(push)
104# pragma warning(disable:4232) /* MSVC extension, dllimport identity */
105#endif
107/*
108 * If a memory-using function (like curl_getenv) is used before
109 * curl_global_init() is called, we need to have these pointers set already.
110 */
111curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc;
112curl_free_callback Curl_cfree = (curl_free_callback)free;
113curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc;
114curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
115curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
117#if defined(_MSC_VER) && defined(_DLL)
118# pragma warning(pop)
119#endif
121#ifdef DEBUGBUILD
122static char *leakpointer;
123#endif
125/**
126 * curl_global_init() globally initializes curl given a bitwise set of the
127 * different features of what to initialize.
128 */
129static CURLcode global_init(long flags, bool memoryfuncs)
131 (void)flags;
133 if(initialized++)
134 return CURLE_OK;
136 if(memoryfuncs) {
137 /* Setup the default memory functions here (again) */
138 Curl_cmalloc = (curl_malloc_callback)malloc;
139 Curl_cfree = (curl_free_callback)free;
140 Curl_crealloc = (curl_realloc_callback)realloc;
141 Curl_cstrdup = (curl_strdup_callback)CURLX_STRDUP_LOW;
142 Curl_ccalloc = (curl_calloc_callback)calloc;
143 }
145#ifdef _WIN32
146 curlx_verify_windows_init();
147 curlx_now_init();
148#endif
150 if(Curl_trc_init()) {
151 DEBUGF(curl_mfprintf(stderr, "Error: Curl_trc_init failed\n"));
152 goto fail;
153 }
155#ifdef USE_WINDOWS_SSPI
156 if(Curl_sspi_global_init()) {
157 DEBUGF(curl_mfprintf(stderr, "Error: Curl_sspi_global_init() failed\n"));
158 goto fail;
159 }
160#endif
162#ifdef USE_WINSOCK
163 /* CURL_GLOBAL_WINSOCK controls the *optional* part of the Windows
164 initialization which is for the Windows sockets library (Winsock). */
165 if(flags & CURL_GLOBAL_WINSOCK) {
166 WSADATA wsa;
167 if(WSAStartup(MAKEWORD(2, 2), &wsa)) {
168 DEBUGF(curl_mfprintf(stderr, "Error: WSAStartup() failed\n"));
169 goto fail;
170 }
171 winsock_initialized = TRUE;
172 }
173#endif
175 if(!Curl_ssl_init()) {
176 DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssl_init failed\n"));
177 goto fail;
178 }
180 if(Curl_hash_global_init()) {
181 DEBUGF(curl_mfprintf(stderr, "Error: Curl_hash_global_init failed\n"));
182 goto fail;
183 }
185 if(!Curl_vquic_init()) {
186 DEBUGF(curl_mfprintf(stderr, "Error: Curl_vquic_init failed\n"));
187 goto fail;
188 }
190 if(Curl_amiga_init()) {
191 DEBUGF(curl_mfprintf(stderr, "Error: Curl_amiga_init failed\n"));
192 goto fail;
193 }
195 if(Curl_macos_init()) {
196 DEBUGF(curl_mfprintf(stderr, "Error: Curl_macos_init failed\n"));
197 goto fail;
198 }
200 if(Curl_async_global_init()) {
201 DEBUGF(curl_mfprintf(stderr, "Error: Curl_async_global_init failed\n"));
202 goto fail;
203 }
205 if(Curl_ssh_init()) {
206 DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssh_init failed\n"));
207 goto fail;
208 }
210#ifdef DEBUGBUILD
211 if(getenv("CURL_GLOBAL_INIT"))
212 /* alloc data that will leak if *cleanup() is not called! */
213 leakpointer = curlx_malloc(1);
214#endif
216 return CURLE_OK;
218fail:
219#ifdef USE_WINSOCK
220 if(winsock_initialized) {
221 WSACleanup();
222 winsock_initialized = FALSE;
223 }
224#endif
225 initialized--; /* undo the increase */
226 return CURLE_FAILED_INIT;
229/**
230 * curl_global_init() globally initializes curl given a bitwise set of the
231 * different features of what to initialize.
232 */
233CURLcode curl_global_init(long flags)
235 CURLcode result;
236 global_init_lock();
238 result = global_init(flags, TRUE);
240 global_init_unlock();
242 return result;
245/*
246 * curl_global_init_mem() globally initializes curl and also registers the
247 * user provided callback routines.
248 */
249CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
250 curl_free_callback f, curl_realloc_callback r,
251 curl_strdup_callback s, curl_calloc_callback c)
253 CURLcode result;
255 /* Invalid input, return immediately */
256 if(!m || !f || !r || !s || !c)
257 return CURLE_FAILED_INIT;
259 global_init_lock();
261 if(initialized) {
262 /* Already initialized, do not do it again, but bump the variable anyway to
263 work like curl_global_init() and require the same amount of cleanup
264 calls. */
265 initialized++;
266 global_init_unlock();
267 return CURLE_OK;
268 }
270 /* set memory functions before global_init() in case it wants memory
271 functions */
272 Curl_cmalloc = m;
273 Curl_cfree = f;
274 Curl_cstrdup = s;
275 Curl_crealloc = r;
276 Curl_ccalloc = c;
278 /* Call the actual init function, but without setting */
279 result = global_init(flags, FALSE);
281 global_init_unlock();
283 return result;
286/**
287 * curl_global_cleanup() globally cleanups curl.
288 */
289void curl_global_cleanup(void)
291 global_init_lock();
293 if(!initialized) {
294 global_init_unlock();
295 return;
296 }
298 if(--initialized) {
299 global_init_unlock();
300 return;
301 }
303 Curl_ssh_cleanup();
304 Curl_ssl_cleanup();
305 Curl_vquic_cleanup();
306 Curl_async_global_cleanup();
307 Curl_amiga_cleanup();
309#ifdef USE_WINSOCK
310 if(winsock_initialized) {
311 WSACleanup();
312 winsock_initialized = FALSE;
313 }
314#endif
316#ifdef USE_WINDOWS_SSPI
317 Curl_sspi_global_cleanup();
318#endif
320#ifdef DEBUGBUILD
321 curlx_free(leakpointer);
322#endif
324 global_init_unlock();
327/**
328 * curl_global_trace() globally initializes curl logging.
329 */
330CURLcode curl_global_trace(const char *config)
332#ifndef CURL_DISABLE_VERBOSE_STRINGS
333 CURLcode result;
334 global_init_lock();
336 result = Curl_trc_opt(config);
338 global_init_unlock();
340 return result;
341#else
342 (void)config;
343 return CURLE_OK;
344#endif
347/*
348 * curl_global_sslset() globally initializes the SSL backend to use.
349 */
350CURLsslset curl_global_sslset(curl_sslbackend id, const char *name,
351 const curl_ssl_backend ***avail)
353 CURLsslset rc;
355 global_init_lock();
357 rc = Curl_init_sslset_nolock(id, name, avail);
359 global_init_unlock();
361 return rc;
364/*
365 * curl_easy_init() is the external interface to alloc, setup and init an
366 * easy handle that is returned. If anything goes wrong, NULL is returned.
367 */
368CURL *curl_easy_init(void)
370 CURLcode result;
371 struct Curl_easy *data;
373 /* Make sure we inited the global SSL stuff */
374 global_init_lock();
376 if(!initialized) {
377 result = global_init(CURL_GLOBAL_DEFAULT, TRUE);
378 if(result) {
379 /* something in the global init failed, return nothing */
380 DEBUGF(curl_mfprintf(stderr, "Error: curl_global_init failed\n"));
381 global_init_unlock();
382 return NULL;
383 }
384 }
385 global_init_unlock();
387 /* We use Curl_open() with undefined URL so far */
388 result = Curl_open(&data);
389 if(result) {
390 DEBUGF(curl_mfprintf(stderr, "Error: Curl_open failed\n"));
391 return NULL;
392 }
394 return data;
397#ifdef DEBUGBUILD
399struct socketmonitor {
400 struct socketmonitor *next; /* the next node in the list or NULL */
401 struct pollfd socket; /* socket info of what to monitor */
402};
404struct events {
405 long ms; /* timeout, run the timeout function when reached */
406 bool msbump; /* set TRUE when timeout is set by callback */
407 int num_sockets; /* number of nodes in the monitor list */
408 struct socketmonitor *list; /* list of sockets to monitor */
409 int running_handles; /* store the returned number */
410};
412#define DEBUG_EV_POLL 0
414/* events_timer
415 *
416 * Callback that gets called with a new value when the timeout should be
417 * updated.
418 */
419static int events_timer(CURLM *multi, /* multi handle */
420 long timeout_ms, /* see above */
421 void *userp) /* private callback pointer */
423 struct events *ev = userp;
424 (void)multi;
425#if DEBUG_EV_POLL
426 curl_mfprintf(stderr, "events_timer: set timeout %ldms\n", timeout_ms);
427#endif
428 ev->ms = timeout_ms;
429 ev->msbump = TRUE;
430 return 0;
433/* poll2cselect
434 *
435 * convert from poll() bit definitions to libcurl's CURL_CSELECT_* ones
436 */
437static int poll2cselect(int pollmask)
439 int omask = 0;
440 if(pollmask & POLLIN)
441 omask |= CURL_CSELECT_IN;
442 if(pollmask & POLLOUT)
443 omask |= CURL_CSELECT_OUT;
444 if(pollmask & POLLERR)
445 omask |= CURL_CSELECT_ERR;
446 return omask;
449/* socketcb2poll
450 *
451 * convert from libcurl' CURL_POLL_* bit definitions to poll()'s
452 */
453static short socketcb2poll(int pollmask)
455 short omask = 0;
456 if(pollmask & CURL_POLL_IN)
457 omask |= POLLIN;
458 if(pollmask & CURL_POLL_OUT)
459 omask |= POLLOUT;
460 return omask;
463/* events_socket
464 *
465 * Callback that gets called with information about socket activity to
466 * monitor.
467 */
468static int events_socket(CURL *easy, /* easy handle */
469 curl_socket_t s, /* socket */
470 int what, /* see above */
471 void *userp, /* private callback
472 pointer */
473 void *socketp) /* private socket
474 pointer */
476 struct events *ev = userp;
477 struct socketmonitor *m;
478 struct socketmonitor *prev = NULL;
479 bool found = FALSE;
480 struct Curl_easy *data = easy;
482#ifdef CURL_DISABLE_VERBOSE_STRINGS
483 (void)easy;
484#endif
485 (void)socketp;
487 m = ev->list;
488 while(m) {
489 if(m->socket.fd == s) {
490 found = TRUE;
491 if(what == CURL_POLL_REMOVE) {
492 struct socketmonitor *nxt = m->next;
493 /* remove this node from the list of monitored sockets */
494 if(prev)
495 prev->next = nxt;
496 else
497 ev->list = nxt;
498 curlx_free(m);
499 infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s);
500 }
501 else {
502 /* The socket 's' is already being monitored, update the activity
503 mask. Convert from libcurl bitmask to the poll one. */
504 m->socket.events = socketcb2poll(what);
505 infof(data, "socket cb: socket %" FMT_SOCKET_T " UPDATED as %s%s", s,
506 (what & CURL_POLL_IN) ? "IN" : "",
507 (what & CURL_POLL_OUT) ? "OUT" : "");
508 }
509 break;
510 }
511 prev = m;
512 m = m->next; /* move to next node */
513 }
515 if(!found) {
516 if(what == CURL_POLL_REMOVE) {
517 /* should not happen if our logic is correct, but is no drama. */
518 DEBUGF(infof(data, "socket cb: asked to REMOVE socket %"
519 FMT_SOCKET_T "but not present!", s));
520 DEBUGASSERT(0);
521 }
522 else {
523 m = curlx_malloc(sizeof(struct socketmonitor));
524 if(m) {
525 m->next = ev->list;
526 m->socket.fd = s;
527 m->socket.events = socketcb2poll(what);
528 m->socket.revents = 0;
529 ev->list = m;
530 infof(data, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s,
531 (what & CURL_POLL_IN) ? "IN" : "",
532 (what & CURL_POLL_OUT) ? "OUT" : "");
533 }
534 else
535 return CURLE_OUT_OF_MEMORY;
536 }
537 }
539 return 0;
542/*
543 * events_setup()
544 *
545 * Do the multi handle setups that only event-based transfers need.
546 */
547static void events_setup(struct Curl_multi *multi, struct events *ev)
549 /* timer callback */
550 curl_multi_setopt(multi, CURLMOPT_TIMERFUNCTION, events_timer);
551 curl_multi_setopt(multi, CURLMOPT_TIMERDATA, ev);
553 /* socket callback */
554 curl_multi_setopt(multi, CURLMOPT_SOCKETFUNCTION, events_socket);
555 curl_multi_setopt(multi, CURLMOPT_SOCKETDATA, ev);
558static CURLcode populate_cpfds(struct curl_pollfds *cpfds, struct events *ev)
560 struct socketmonitor *m;
561 CURLcode result = CURLE_OK;
563 Curl_pollfds_reset(cpfds);
564 for(m = ev->list; m && !result; m = m->next) {
565 result = Curl_pollfds_add_sock(cpfds, m->socket.fd, m->socket.events);
566#if DEBUG_EV_POLL
567 if(!result)
568 curl_mfprintf(stderr, "poll() %d check socket %d\n",
569 cpfds->n - 1, cpfds->pfds[cpfds->n - 1].fd);
570#endif
571 }
572 return result;
575static CURLcode poll_cpfds(struct events *ev,
576 struct curl_pollfds *cpfds,
577 int *pollrc)
579 if(cpfds->n) {
580 /* wait for activity or timeout */
581#if DEBUG_EV_POLL
582 curl_mfprintf(stderr, "poll(numfds=%u, timeout=%ldms)\n",
583 cpfds->n, ev->ms);
584#endif
585 *pollrc = Curl_poll(cpfds->pfds, cpfds->n, ev->ms);
586#if DEBUG_EV_POLL
587 curl_mfprintf(stderr, "poll(numfds=%u, timeout=%ldms) -> %d\n",
588 cpfds->n, ev->ms, *pollrc);
589#endif
590 if(*pollrc < 0)
591 return CURLE_UNRECOVERABLE_POLL;
592 }
593 else {
594#if DEBUG_EV_POLL
595 curl_mfprintf(stderr, "poll, but no fds, wait timeout=%ldms\n", ev->ms);
596#endif
597 *pollrc = 0;
598 if(ev->ms > 0)
599 curlx_wait_ms(ev->ms);
600 }
601 return CURLE_OK;
604/* wait_or_timeout()
605 *
606 * waits for activity on any of the given sockets, or the timeout to trigger.
607 */
608static CURLcode wait_or_timeout(struct Curl_multi *multi, struct events *ev)
610 struct pollfd fds_on_stack[8];
611 struct curl_pollfds cpfds;
612 bool done = FALSE;
613 CURLMcode mresult = CURLM_OK;
614 CURLcode result = CURLE_OK;
616 Curl_pollfds_init(&cpfds, fds_on_stack, CURL_ARRAYSIZE(fds_on_stack));
617 while(!done) {
618 CURLMsg *msg;
619 int pollrc;
620 struct curltime start;
622 result = populate_cpfds(&cpfds, ev);
623 if(result)
624 goto out;
626 /* get the time stamp to use to figure out how long poll takes */
627 curlx_pnow(&start);
629 result = poll_cpfds(ev, &cpfds, &pollrc);
630 if(result)
631 goto out;
633 ev->msbump = FALSE; /* reset here */
635 if(!pollrc) {
636 /* timeout! */
637 ev->ms = 0;
638#if DEBUG_EV_POLL
639 curl_mfprintf(stderr, "call curl_multi_socket_action(TIMEOUT)\n");
640#endif
641 mresult = curl_multi_socket_action(multi, CURL_SOCKET_TIMEOUT, 0,
642 &ev->running_handles);
643 }
644 else {
645 /* here pollrc is > 0 */
646 /* loop over the monitored sockets to see which ones had activity */
647 unsigned int i;
648 for(i = 0; i < cpfds.n; i++) {
649 if(cpfds.pfds[i].revents) {
650 /* socket activity, tell libcurl */
651 int act = poll2cselect(cpfds.pfds[i].revents); /* convert */
653 /* sending infof "randomly" to the first easy handle */
654 infof(multi->admin, "call curl_multi_socket_action(socket "
655 "%" FMT_SOCKET_T ")", (curl_socket_t)cpfds.pfds[i].fd);
656 mresult = curl_multi_socket_action(multi, cpfds.pfds[i].fd, act,
657 &ev->running_handles);
658 }
659 }
661 if(!ev->msbump && ev->ms >= 0) {
662 /* If nothing updated the timeout, we decrease it by the spent time.
663 * If it was updated, it has the new timeout time stored already.
664 */
665 timediff_t spent_ms = curlx_timediff_ms(curlx_now(), start);
666 if(spent_ms > 0) {
667#if DEBUG_EV_POLL
668 curl_mfprintf(stderr, "poll timeout %ldms not updated, decrease by "
669 "time spent %ldms\n", ev->ms, (long)spent_ms);
670#endif
671 if(spent_ms > ev->ms)
672 ev->ms = 0;
673 else
674 ev->ms -= (long)spent_ms;
675 }
676 }
677 }
679 if(mresult) {
680 result = CURLE_URL_MALFORMAT;
681 goto out;
682 }
684 /* we do not really care about the "msgs_in_queue" value returned in the
685 second argument */
686 msg = curl_multi_info_read(multi, &pollrc);
687 if(msg) {
688 result = msg->data.result;
689 done = TRUE;
690 }
691 }
692out:
693 Curl_pollfds_cleanup(&cpfds);
694 return result;
697/* easy_events()
698 *
699 * Runs a transfer in a blocking manner using the events-based API
700 */
701static CURLcode easy_events(struct Curl_multi *multi)
703 /* this struct is made static to allow it to be used after this function
704 returns and curl_multi_remove_handle() is called */
705 static struct events evs = { -1, FALSE, 0, NULL, 0 };
707 /* if running event-based, do some further multi inits */
708 events_setup(multi, &evs);
710 return wait_or_timeout(multi, &evs);
712#else /* DEBUGBUILD */
713/* when not built with debug, this function does not exist */
714#define easy_events(x) CURLE_NOT_BUILT_IN
715#endif
717static CURLcode easy_transfer(struct Curl_multi *multi)
719 bool done = FALSE;
720 CURLMcode mresult = CURLM_OK;
721 CURLcode result = CURLE_OK;
723 while(!done && !mresult) {
724 int still_running = 0;
726 mresult = curl_multi_poll(multi, NULL, 0, 1000, NULL);
728 if(!mresult)
729 mresult = curl_multi_perform(multi, &still_running);
731 /* only read 'still_running' if curl_multi_perform() return OK */
732 if(!mresult && !still_running) {
733 int rc;
734 CURLMsg *msg = curl_multi_info_read(multi, &rc);
735 if(msg) {
736 result = msg->data.result;
737 done = TRUE;
738 }
739 }
740 }
742 /* Make sure to return some kind of error if there was a multi problem */
743 if(mresult) {
744 result = (mresult == CURLM_OUT_OF_MEMORY) ? CURLE_OUT_OF_MEMORY :
745 /* The other multi errors should never happen, so return
746 something suitably generic */
747 CURLE_BAD_FUNCTION_ARGUMENT;
748 }
750 return result;
753/*
754 * easy_perform() is the internal interface that performs a blocking
755 * transfer as previously setup.
756 *
757 * CONCEPT: This function creates a multi handle, adds the easy handle to it,
758 * runs curl_multi_perform() until the transfer is done, then detaches the
759 * easy handle, destroys the multi handle and returns the easy handle's return
760 * code.
761 *
762 * REALITY: it cannot create and destroy the multi handle that easily. It
763 * needs to keep it around since if this easy handle is used again by this
764 * function, the same multi handle must be reused so that the same pools and
765 * caches can be used.
766 *
767 * DEBUG: if 'events' is set TRUE, this function will use a replacement engine
768 * instead of curl_multi_perform() and use curl_multi_socket_action().
769 */
770static CURLcode easy_perform(struct Curl_easy *data, bool events)
772 struct Curl_multi *multi;
773 CURLMcode mresult;
774 CURLcode result = CURLE_OK;
775 struct Curl_sigpipe_ctx sigpipe_ctx;
777 if(!data)
778 return CURLE_BAD_FUNCTION_ARGUMENT;
780 if(data->set.errorbuffer)
781 /* clear this as early as possible */
782 data->set.errorbuffer[0] = 0;
784 data->state.os_errno = 0;
786 if(data->multi) {
787 failf(data, "easy handle already used in multi handle");
788 return CURLE_FAILED_INIT;
789 }
791 /* if the handle has a connection still attached (it is/was a connect-only
792 handle) then disconnect before performing */
793 if(data->conn) {
794 struct connectdata *conn = data->conn;
795 Curl_detach_connection(data);
796 Curl_conn_close(data, conn, TRUE);
797 DEBUGASSERT(!data->conn);
798 }
800 if(data->multi_easy)
801 multi = data->multi_easy;
802 else {
803 /* this multi handle will only ever have a single easy handle attached to
804 it, so make it use minimal hash sizes */
805 multi = Curl_multi_handle(16, 1, 3, 7, 3);
806 if(!multi)
807 return CURLE_OUT_OF_MEMORY;
808 }
810 if(Curl_api_multi_is_in_callback(multi))
811 return CURLE_RECURSIVE_API_CALL;
813 /* Copy relevant easy options to the multi handle */
814 curl_multi_setopt(multi, CURLMOPT_MAXCONNECTS, (long)data->set.maxconnects);
815 curl_multi_setopt(multi, CURLMOPT_QUICK_EXIT, (long)data->set.quick_exit);
817 data->multi_easy = NULL; /* pretend it does not exist */
818 mresult = Curl_multi_add_handle(multi, data);
819 if(mresult) {
820 curl_multi_cleanup(multi);
821 if(mresult == CURLM_OUT_OF_MEMORY)
822 return CURLE_OUT_OF_MEMORY;
823 return CURLE_FAILED_INIT;
824 }
826 /* assign this after curl_multi_add_handle() */
827 data->multi_easy = multi;
829 sigpipe_init(&sigpipe_ctx);
830 sigpipe_apply(data, &sigpipe_ctx);
832 /* run the transfer */
833 result = events ? easy_events(multi) : easy_transfer(multi);
835 /* ignoring the return code is not nice, but atm we cannot really handle
836 a failure here, room for future improvement! */
837 (void)Curl_multi_remove_handle(multi, data);
839 sigpipe_restore(&sigpipe_ctx);
841 /* The multi handle is kept alive, owned by the easy handle */
842 return result;
845/*
846 * curl_easy_perform() is the external interface that performs a blocking
847 * transfer as previously setup.
848 */
849CURLcode curl_easy_perform(CURL *curl)
851 struct Curl_eapi_guard guard = { 0 };
852 CURLcode result;
854 if(CURL_EAPI_ENTER(&guard, curl, easy_perform, &result)) {
855 result = easy_perform(curl, FALSE);
856 }
857 CURL_EAPI_LEAVE(&guard);
858 return result;
861#ifdef DEBUGBUILD
862/*
863 * curl_easy_perform_ev() is the external interface that performs a blocking
864 * transfer using the event-based API internally.
865 */
866CURLcode curl_easy_perform_ev(struct Curl_easy *easy)
868 struct Curl_eapi_guard guard;
869 CURLcode result;
871 if(CURL_EAPI_ENTER(&guard, easy, easy_perform_ev, &result)) {
872 result = easy_perform(easy, TRUE);
873 }
874 CURL_EAPI_LEAVE(&guard);
875 return result;
877#endif
879/*
880 * curl_easy_cleanup() is the external interface to cleaning/freeing the given
881 * easy handle.
882 */
883void curl_easy_cleanup(CURL *curl)
885 struct Curl_eapi_guard guard;
887 if(CURL_EAPI_ENTER(&guard, curl, easy_cleanup, NULL)) {
888 struct Curl_easy *data = curl;
889 struct Curl_sigpipe_ctx sigpipe_ctx;
890 sigpipe_ignore(data, &sigpipe_ctx);
891 Curl_close(&data);
892 sigpipe_restore(&sigpipe_ctx);
893 }
894 CURL_EAPI_LEAVE(&guard);
897/*
898 * curl_easy_getinfo() is an external interface that allows an app to retrieve
899 * information from a performed transfer and similar.
900 */
901#undef curl_easy_getinfo
902CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info, ...)
904 struct Curl_eapi_guard guard;
905 CURLcode result;
907 if(CURL_EAPI_ENTER(&guard, curl, easy_getinfo, &result)) {
908 struct Curl_easy *data = curl;
909 va_list arg;
910 void *paramp;
912 va_start(arg, info);
913 paramp = va_arg(arg, void *);
915 result = Curl_getinfo(data, info, paramp);
917 va_end(arg);
918 }
919 CURL_EAPI_LEAVE(&guard);
920 return result;
923static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
925 CURLcode result = CURLE_OK;
926 enum dupblob j;
928 /* Copy src->set into dst->set first, then deal with the strings
929 afterwards */
930 dst->set = src->set;
931#if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API)
932 dst->set.mimepostp = NULL;
933#endif
934 dst->set.str_copypostfields = NULL;
936 Curl_u8_strset_init(&dst->set.strings);
937 /* clear all dest string and blob pointers first, in case we error out
938 mid-function */
939 memset(dst->set.blobs, 0, BLOB_LAST * sizeof(struct curl_blob *));
941 /* duplicate all strings */
942 result = Curl_u8_strset_copy(&dst->set.strings, &src->set.strings);
943 if(result)
944 return result;
946 /* duplicate all blobs */
947 for(j = (enum dupblob)0; j < BLOB_LAST; j++) {
948 result = Curl_setblobopt(&dst->set.blobs[j], src->set.blobs[j]);
949 if(result)
950 return result;
951 }
953 /* duplicate memory areas pointed to */
954 if(src->set.str_copypostfields) {
955 if(src->set.postfieldsize == -1)
956 dst->set.str_copypostfields = curlx_strdup(src->set.str_copypostfields);
957 else
958 /* postfieldsize is curl_off_t, curlx_memdup0() takes a size_t ... */
959 dst->set.str_copypostfields =
960 curlx_memdup0(src->set.str_copypostfields,
961 curlx_sotouz(src->set.postfieldsize));
962 if(!dst->set.str_copypostfields)
963 return CURLE_OUT_OF_MEMORY;
964 /* point to the new copy */
965 dst->set.postfields = dst->set.str_copypostfields;
966 }
968#if !defined(CURL_DISABLE_MIME) || !defined(CURL_DISABLE_FORM_API)
969 if(src->set.mimepostp) {
970 /* Duplicate mime data. Get a mimepost struct for the clone as well */
971 dst->set.mimepostp = curlx_malloc(sizeof(*dst->set.mimepostp));
972 if(!dst->set.mimepostp)
973 return CURLE_OUT_OF_MEMORY;
975 Curl_mime_initpart(dst->set.mimepostp);
976 result = Curl_mime_duppart(dst, dst->set.mimepostp, src->set.mimepostp);
977 if(result)
978 return result;
979 }
980#endif
982 if(src->set.resolve)
983 dst->state.resolve = dst->set.resolve;
985 return result;
988static void dupeasy_meta_freeentry(void *p)
990 (void)p;
991 /* Always FALSE. Cannot use a 0 assert here since compilers
992 * are not in agreement if they then want a NORETURN attribute or
993 * not. *sigh* */
994 DEBUGASSERT(!p);
997/*
998 * curl_easy_duphandle() is an external interface to allow duplication of a
999 * given input easy handle. The returned handle will be a new working handle
1000 * with all options set exactly as the input source handle.
1001 */
1002CURL *curl_easy_duphandle(CURL *curl)
1004 struct Curl_eapi_guard guard;
1005 struct Curl_easy *outcurl = NULL;
1007 if(CURL_EAPI_ENTER(&guard, curl, easy_duphandle, NULL)) {
1008 struct Curl_easy *data = curl;
1010 outcurl = curlx_calloc(1, sizeof(struct Curl_easy));
1011 if(!outcurl)
1012 goto fail;
1014 /*
1015 * We setup a few buffers we need. We should probably make them
1016 * get setup on-demand in the code, as that would probably decrease
1017 * the likeliness of us forgetting to init a buffer here in the future.
1018 */
1019 outcurl->set.buffer_size = data->set.buffer_size;
1021 Curl_hash_init(&outcurl->meta_hash, 23, CURL_HASH_TYPE_BYTES,
1022 dupeasy_meta_freeentry);
1023 curlx_dyn_init(&outcurl->state.headerb, CURL_MAX_HTTP_HEADER);
1024 Curl_bufref_init(&outcurl->state.url);
1025 Curl_bufref_init(&outcurl->state.referer);
1026 Curl_netrc_init(&outcurl->state.netrc);
1028 /* the connection pool is setup on demand */
1029 outcurl->state.last_conn_id = -1;
1030 outcurl->state.last_cpid = UINT32_MAX;
1031 outcurl->id = -1;
1032 outcurl->mid = UINT32_MAX;
1033 outcurl->master_mid = UINT32_MAX;
1035#ifndef CURL_DISABLE_HTTP
1036 Curl_llist_init(&outcurl->state.httphdrs, NULL);
1037#endif
1038 Curl_initinfo(outcurl);
1040 /* copy all userdefined values */
1041 if(dupset(outcurl, data))
1042 goto fail;
1044 outcurl->progress.hide = data->progress.hide;
1045 outcurl->progress.callback = data->progress.callback;
1047#ifndef CURL_DISABLE_COOKIES
1048 outcurl->state.cookielist = NULL;
1049 if(data->cookies && data->state.cookie_engine) {
1050 /* If cookies are enabled in the parent handle, we enable them
1051 in the clone as well! */
1052 outcurl->cookies = Curl_cookie_init();
1053 if(!outcurl->cookies)
1054 goto fail;
1055 outcurl->state.cookie_engine = TRUE;
1058 if(data->state.cookielist) {
1059 outcurl->state.cookielist = Curl_slist_duplicate(data->state.cookielist);
1060 if(!outcurl->state.cookielist)
1061 goto fail;
1063#endif
1065 if(Curl_bufref_ptr(&data->state.url)) {
1066 Curl_bufref_set(&outcurl->state.url,
1067 Curl_bufref_dup(&data->state.url), 0,
1068 curl_free);
1069 if(!Curl_bufref_ptr(&outcurl->state.url))
1070 goto fail;
1072 if(Curl_bufref_ptr(&data->state.referer)) {
1073 Curl_bufref_set(&outcurl->state.referer,
1074 Curl_bufref_dup(&data->state.referer), 0,
1075 curl_free);
1076 if(!Curl_bufref_ptr(&outcurl->state.referer))
1077 goto fail;
1080#ifndef CURL_DISABLE_ALTSVC
1081 if(data->asi) {
1082 const char *str;
1083 outcurl->asi = Curl_altsvc_init();
1084 if(!outcurl->asi)
1085 goto fail;
1086 str = CURL_EASY_STR(outcurl, STRING_ALTSVC);
1087 if(str)
1088 (void)Curl_altsvc_load(outcurl->asi, str);
1090#endif
1091#ifndef CURL_DISABLE_HSTS
1092 if(data->hsts) {
1093 const char *str;
1094 outcurl->hsts = Curl_hsts_init();
1095 if(!outcurl->hsts)
1096 goto fail;
1097 str = CURL_EASY_STR(outcurl, STRING_HSTS);
1098 if(str)
1099 (void)Curl_hsts_loadfile(outcurl, outcurl->hsts, str);
1100 (void)Curl_hsts_loadcb(outcurl, outcurl->hsts);
1102 /* Copy entries learned at runtime. (E.g. Strict-Transport-Security
1103 headers.) */
1104 if(Curl_hsts_copy(outcurl->hsts, data->hsts))
1105 goto fail;
1107#endif
1109 /* we reach this point and thus we are OK */
1110 outcurl->magic = CURLEASY_MAGIC_NUMBER;
1112 CURL_EAPI_LEAVE(&guard);
1113 return outcurl;
1115fail:
1116 if(outcurl) {
1117#ifndef CURL_DISABLE_COOKIES
1118 curlx_free(outcurl->cookies);
1119#endif
1120 curlx_dyn_free(&outcurl->state.headerb);
1121 Curl_altsvc_cleanup(&outcurl->asi);
1122 Curl_hsts_cleanup(&outcurl->hsts);
1123 Curl_freeset(outcurl);
1124 curlx_free(outcurl);
1127 CURL_EAPI_LEAVE(&guard);
1128 return NULL;
1132 * curl_easy_reset() is an external interface that allows an app to re-
1133 * initialize a session handle to the default values.
1134 */
1135void curl_easy_reset(CURL *curl)
1137 struct Curl_eapi_guard guard;
1139 if(CURL_EAPI_ENTER(&guard, curl, easy_reset, NULL)) {
1140 struct Curl_easy *data = curl;
1142 data->state.last_conn_id = -1; /* clear remembered connection id */
1143 data->state.last_cpid = UINT32_MAX;
1144 Curl_req_hard_reset(&data->req, data);
1145 Curl_hash_clean(&data->meta_hash);
1147 /* clear all meta data */
1148 Curl_meta_reset(data);
1149 /* zero out UserDefined data: */
1150 Curl_freeset(data);
1151 memset(&data->set, 0, sizeof(struct UserDefined));
1152 Curl_init_userdefined(data);
1154 /* zero out Progress data: */
1155 memset(&data->progress, 0, sizeof(struct Progress));
1157 /* zero out PureInfo data: */
1158 Curl_initinfo(data);
1160 data->progress.hide = TRUE;
1162 /* zero out authentication data: */
1163 memset(&data->state.authhost, 0, sizeof(struct auth));
1164 memset(&data->state.authproxy, 0, sizeof(struct auth));
1166#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
1167 Curl_http_auth_cleanup_digest(data);
1168#endif
1169 data->master_mid = UINT32_MAX;
1171 CURL_EAPI_LEAVE(&guard);
1175 * curl_easy_pause() allows an application to pause or unpause a specific
1176 * transfer and direction. This function sets the full new state for the
1177 * current connection this easy handle operates on.
1179 * NOTE: if you have the receiving paused and you call this function to remove
1180 * the pausing, you may get your write callback called at this point.
1182 * Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
1184 * NOTE: This is one of few API functions that are allowed to be called from
1185 * within a callback.
1186 */
1187CURLcode curl_easy_pause(CURL *curl, int action)
1189 struct Curl_eapi_guard guard;
1190 CURLcode result = CURLE_OK;
1192 if(CURL_EAPI_ENTER(&guard, curl, easy_pause, &result)) {
1193 bool changed = FALSE;
1194 struct Curl_easy *data = curl;
1195 bool recv_paused, recv_paused_new;
1196 bool send_paused, send_paused_new;
1198 if(!data->conn) {
1199 /* crazy input, do not continue */
1200 result = CURLE_BAD_FUNCTION_ARGUMENT;
1201 goto out;
1204 recv_paused = Curl_xfer_recv_is_paused(data);
1205 recv_paused_new = (action & CURLPAUSE_RECV);
1206 send_paused = Curl_xfer_send_is_paused(data);
1207 send_paused_new = (action & CURLPAUSE_SEND);
1209 if((send_paused != send_paused_new) ||
1210 (send_paused_new != Curl_creader_is_paused(data))) {
1211 changed = TRUE;
1212 result = Curl_1st_fatal(
1213 result, Curl_xfer_pause_send(data, send_paused_new));
1216 if(recv_paused != recv_paused_new) {
1217 changed = TRUE;
1218 result = Curl_1st_fatal(
1219 result, Curl_xfer_pause_recv(data, recv_paused_new));
1222 /* If not completely pausing both directions, run again in any case. */
1223 if(!Curl_xfer_is_blocked(data)) {
1224 /* reset the too-slow time keeper */
1225 data->state.keeps_speed.tv_sec = 0;
1226 if(data->multi) {
1227 Curl_multi_mark_dirty(data); /* make it run */
1228 /* On changes, tell application to update its timers. */
1229 if(changed && Curl_update_timer(data->multi) && !result)
1230 result = CURLE_ABORTED_BY_CALLBACK;
1234 if(!result && changed && !data->state.done && data->multi &&
1235 /* pause/unpausing may result in multi event changes */
1236 Curl_multi_ev_assess_xfer(data->multi, data))
1237 result = CURLE_ABORTED_BY_CALLBACK;
1239out:
1240 CURL_EAPI_LEAVE(&guard);
1241 return result;
1244static CURLcode easy_connection(struct Curl_easy *data,
1245 struct connectdata **connp)
1247 curl_socket_t sfd;
1249 if(!data)
1250 return CURLE_BAD_FUNCTION_ARGUMENT;
1252 /* only allow these to be called on handles with CURLOPT_CONNECT_ONLY */
1253 if(!data->set.connect_only) {
1254 failf(data, "CONNECT_ONLY is required");
1255 return CURLE_UNSUPPORTED_PROTOCOL;
1258 sfd = Curl_getconnectinfo(data, connp);
1260 if(sfd == CURL_SOCKET_BAD) {
1261 failf(data, "Failed to get last socket used for connection #%" FMT_OFF_T,
1262 data->state.last_conn_id);
1263 return CURLE_UNSUPPORTED_PROTOCOL;
1266 return CURLE_OK;
1270 * Receives data from the connected socket. Use after successful
1271 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1272 * Returns CURLE_OK on success, error code on error.
1273 */
1274CURLcode Curl_easy_recv(struct Curl_easy *data,
1275 void *buffer, size_t buflen, size_t *n)
1277 CURLcode result;
1278 struct connectdata *c;
1280 result = easy_connection(data, &c);
1281 if(result)
1282 return result;
1284 if(!data->conn)
1285 /* on first invoke, the transfer has been detached from the connection and
1286 needs to be reattached */
1287 Curl_attach_connection(data, c, TRUE);
1289 *n = 0;
1290 return Curl_conn_recv(data, FIRSTSOCKET, buffer, buflen, n);
1293CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n)
1295 struct Curl_eapi_guard guard;
1296 CURLcode result;
1298 if(CURL_EAPI_ENTER(&guard, curl, easy_recv, &result)) {
1299 if(!n || (buflen && !buffer)) {
1300 result = CURLE_BAD_FUNCTION_ARGUMENT;
1301 goto out;
1303 result = Curl_easy_recv(curl, buffer, buflen, n);
1305out:
1306 CURL_EAPI_LEAVE(&guard);
1307 return result;
1310#ifndef CURL_DISABLE_WEBSOCKETS
1311CURLcode Curl_connect_only_attach(struct Curl_easy *data)
1313 CURLcode result;
1314 struct connectdata *c = NULL;
1316 result = easy_connection(data, &c);
1317 if(result)
1318 return result;
1320 if(!data->conn)
1321 /* on first invoke, the transfer has been detached from the connection and
1322 needs to be reattached */
1323 Curl_attach_connection(data, c, TRUE);
1325 return CURLE_OK;
1327#endif /* !CURL_DISABLE_WEBSOCKETS */
1330 * Sends data over the connected socket.
1332 * This is the private internal version of curl_easy_send()
1333 */
1334CURLcode Curl_senddata(struct Curl_easy *data, const void *buffer,
1335 size_t buflen, size_t *n)
1337 CURLcode result;
1338 struct connectdata *c = NULL;
1339 struct Curl_sigpipe_ctx sigpipe_ctx;
1341 *n = 0;
1342 result = easy_connection(data, &c);
1343 if(result)
1344 return result;
1346 if(!data->conn)
1347 /* on first invoke, the transfer has been detached from the connection and
1348 needs to be reattached */
1349 Curl_attach_connection(data, c, TRUE);
1351 sigpipe_ignore(data, &sigpipe_ctx);
1352 result = Curl_conn_send(data, FIRSTSOCKET, buffer, buflen, FALSE, n);
1353 sigpipe_restore(&sigpipe_ctx);
1355 if(result && result != CURLE_AGAIN)
1356 return CURLE_SEND_ERROR;
1357 return result;
1361 * Sends data over the connected socket. Use after successful
1362 * curl_easy_perform() with CURLOPT_CONNECT_ONLY option.
1363 */
1364CURLcode curl_easy_send(CURL *curl, const void *buffer, size_t buflen,
1365 size_t *n)
1367 struct Curl_eapi_guard guard;
1368 CURLcode result;
1370 if(CURL_EAPI_ENTER(&guard, curl, easy_send, &result)) {
1371 struct Curl_easy *data = curl;
1372 size_t written = 0;
1374 if(!n || (buflen && !buffer)) {
1375 result = CURLE_BAD_FUNCTION_ARGUMENT;
1376 goto out;
1378 result = Curl_senddata(data, buffer, buflen, &written);
1379 *n = written;
1381out:
1382 CURL_EAPI_LEAVE(&guard);
1383 return result;
1387 * Performs connection upkeep for the given session handle.
1388 */
1389CURLcode curl_easy_upkeep(CURL *curl)
1391 struct Curl_eapi_guard guard;
1392 CURLcode result;
1394 if(CURL_EAPI_ENTER(&guard, curl, easy_upkeep, &result)) {
1395 /* Use the common function to keep connections alive. */
1396 result = Curl_cpool_upkeep((struct Curl_easy *)curl);
1398 CURL_EAPI_LEAVE(&guard);
1399 return result;
1402CURLcode curl_easy_ssls_import(CURL *curl, const char *session_key,
1403 const unsigned char *shmac, size_t shmac_len,
1404 const unsigned char *sdata, size_t sdata_len)
1406#if defined(USE_SSL) && defined(USE_SSLS_EXPORT)
1407 struct Curl_eapi_guard guard;
1408 CURLcode result;
1410 if(CURL_EAPI_ENTER(&guard, curl, easy_ssls_import, &result)) {
1411 if(!sdata || !sdata_len)
1412 result = CURLE_BAD_FUNCTION_ARGUMENT;
1413 else
1414 result = Curl_ssl_session_import((struct Curl_easy *)curl, session_key,
1415 shmac, shmac_len, sdata, sdata_len);
1417 CURL_EAPI_LEAVE(&guard);
1418 return result;
1419#else
1420 (void)curl;
1421 (void)session_key;
1422 (void)shmac;
1423 (void)shmac_len;
1424 (void)sdata;
1425 (void)sdata_len;
1426 return CURLE_NOT_BUILT_IN;
1427#endif
1430CURLcode curl_easy_ssls_export(CURL *curl,
1431 curl_ssls_export_cb *export_fn,
1432 void *userptr)
1434#if defined(USE_SSL) && defined(USE_SSLS_EXPORT)
1435 struct Curl_eapi_guard guard;
1436 CURLcode result;
1438 if(CURL_EAPI_ENTER(&guard, curl, easy_ssls_export, &result)) {
1439 if(!export_fn)
1440 result = CURLE_BAD_FUNCTION_ARGUMENT;
1441 else
1442 result = Curl_ssl_session_export((struct Curl_easy *)curl,
1443 export_fn, userptr);
1445 CURL_EAPI_LEAVE(&guard);
1446 return result;
1447#else
1448 (void)curl;
1449 (void)export_fn;
1450 (void)userptr;
1451 return CURLE_NOT_BUILT_IN;
1452#endif
1455CURLcode Curl_meta_set(struct Curl_easy *data, const char *key,
1456 void *meta_data, Curl_meta_dtor *meta_dtor)
1458 DEBUGASSERT(meta_data); /* never set to NULL */
1459 if(!Curl_hash_add2(&data->meta_hash, key, strlen(key) + 1,
1460 meta_data, meta_dtor)) {
1461 meta_dtor(key, strlen(key) + 1, meta_data);
1462 return CURLE_OUT_OF_MEMORY;
1464 return CURLE_OK;
1467void Curl_meta_remove(struct Curl_easy *data, const char *key)
1469 Curl_hash_delete(&data->meta_hash, key, strlen(key) + 1);
1472void *Curl_meta_get(struct Curl_easy *data, const char *key)
1474 return Curl_hash_pick(&data->meta_hash, key, strlen(key) + 1);
1477void Curl_meta_reset(struct Curl_easy *data)
1479 Curl_hash_clean(&data->meta_hash);
Diagnostics4 git calls · 55 ms
CallStatusSizeTime055 ms
discover200152 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
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 · hit27 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=23
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=23
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=4
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
fetch20012 KiB · hit24 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=24
git.response.bytes=12077
git.response.cache=HIT
git.response.duration_ms=24
git.fetch.wants=58d3098edfa36b14e970fe5400db8cf579de43d2
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=12077
git.pkt.payload.max=12056
git.sideband.band1.bytes=12055
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
a5eb46a21fd85aae
Request
193a6d77…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format