Artifactspublic-v0

curl

master
ply4 git calls30 ms296 KiB3 cachedprotocol v2
914 lines29 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
41#include <signal.h>
43#ifdef HAVE_SYS_PARAM_H
44#include <sys/param.h>
45#endif
47#ifdef HAVE_SYS_SELECT_H
48#include <sys/select.h>
49#elif defined(HAVE_UNISTD_H)
50#include <unistd.h>
51#endif
53#ifndef HAVE_SOCKET
54#error "We cannot compile without socket() support"
55#endif
57#include "urldata.h"
59#include "cfilters.h"
60#include "cw-out.h"
61#include "transfer.h"
62#include "sendf.h"
63#include "curl_trc.h"
64#include "progress.h"
65#include "http.h"
66#include "url.h"
67#include "getinfo.h"
68#include "multiif.h"
69#include "connect.h"
70#include "hsts.h"
71#include "setopt.h"
72#include "headers.h"
73#include "bufref.h"
74#include "rtsp.h"
76#if !defined(CURL_DISABLE_HTTP) || !defined(CURL_DISABLE_SMTP) || \
77 !defined(CURL_DISABLE_IMAP)
78/*
79 * checkheaders() checks the linked list of custom headers for a
80 * particular header (prefix). Provide the prefix without colon!
81 *
82 * Returns a pointer to the first matching header or NULL if none matched.
83 */
84char *Curl_checkheaders(const struct Curl_easy *data,
85 const char *thisheader,
86 const size_t thislen)
88 struct curl_slist *head;
89 DEBUGASSERT(thislen);
90 DEBUGASSERT(thisheader[thislen - 1] != ':');
92 for(head = data->set.headers; head; head = head->next) {
93 if(curl_strnequal(head->data, thisheader, thislen) &&
94 Curl_headersep(head->data[thislen]))
95 return head->data;
96 }
98 return NULL;
100#endif
102static int data_pending(struct Curl_easy *data, bool rcvd_eagain)
104 struct connectdata *conn = data->conn;
106 if(conn->scheme->protocol & PROTO_FAMILY_FTP)
107 return Curl_conn_data_pending(data, SECONDARYSOCKET);
109 /* in the case of libssh2, we can never be really sure that we have emptied
110 its internal buffers so we MUST always try until we get EAGAIN back */
111 return (!rcvd_eagain &&
112 conn->scheme->protocol & (CURLPROTO_SCP | CURLPROTO_SFTP)) ||
113 Curl_conn_data_pending(data, FIRSTSOCKET);
116/*
117 * Check to see if CURLOPT_TIMECONDITION was met by comparing the time of the
118 * remote document with the time provided by CURLOPT_TIMEVAL
119 */
120bool Curl_meets_timecondition(struct Curl_easy *data, time_t timeofdoc)
122 if((timeofdoc == 0) || (data->set.timevalue == 0))
123 return TRUE;
125 switch(data->set.timecondition) {
126 case CURL_TIMECOND_IFMODSINCE:
127 default:
128 if(timeofdoc <= data->set.timevalue) {
129 infof(data, "The requested document is not new enough");
130 data->info.timecond = TRUE;
131 return FALSE;
132 }
133 break;
134 case CURL_TIMECOND_IFUNMODSINCE:
135 if(timeofdoc >= data->set.timevalue) {
136 infof(data, "The requested document is not old enough");
137 data->info.timecond = TRUE;
138 return FALSE;
139 }
140 break;
141 }
143 return TRUE;
146static CURLcode xfer_recv_shutdown(struct Curl_easy *data, bool *done)
148 if(!data || !data->conn)
149 return CURLE_FAILED_INIT;
150 return Curl_cshutdn_try_once_idx(data, data->conn->recv_idx, done);
153static bool xfer_recv_shutdown_started(struct Curl_easy *data)
155 if(!data || !data->conn)
156 return FALSE;
157 return CURL_CONN_IN_SHUTDOWN(data->conn, data->conn->recv_idx);
160CURLcode Curl_xfer_send_shutdown(struct Curl_easy *data, bool *done)
162 if(!data || !data->conn)
163 return CURLE_FAILED_INIT;
164 return Curl_cshutdn_try_once_idx(data, data->conn->send_idx, done);
167/**
168 * Receive raw response data for the transfer.
169 * @param data the transfer
170 * @param buf buffer to keep response data received
171 * @param blen length of `buf`
172 * @param eos_reliable if EOS detection in underlying connection is reliable
173 * @return number of bytes read or -1 for error
174 */
175static CURLcode xfer_recv_resp(struct Curl_easy *data,
176 char *buf, size_t blen,
177 bool eos_reliable,
178 size_t *pnread)
180 CURLcode result;
182 DEBUGASSERT(blen > 0);
183 *pnread = 0;
184 /* If we are reading BODY data and the connection does NOT handle EOF
185 * and we know the size of the BODY data, limit the read amount */
186 if(!eos_reliable && !data->req.header && data->req.size != -1) {
187 blen = curlx_sotouz_range(data->req.size - data->req.bytecount, 0, blen);
188 }
189 else if(xfer_recv_shutdown_started(data)) {
190 /* we already received everything. Do not try more. */
191 blen = 0;
192 }
194 if(blen) {
195 result = Curl_xfer_recv(data, buf, blen, pnread);
196 if(result)
197 return result;
198 }
200 if(*pnread == 0) {
201 if(data->req.shutdown) {
202 bool done;
203 result = xfer_recv_shutdown(data, &done);
204 if(result)
205 return result;
206 if(!done) {
207 return CURLE_AGAIN;
208 }
209 }
210 DEBUGF(infof(data, "sendrecv_dl: we are done"));
211 }
212 return CURLE_OK;
215/*
216 * Go ahead and do a read if we have a readable socket or if
217 * the stream was rewound (in which case we have data in a
218 * buffer)
219 */
220static CURLcode sendrecv_dl(struct Curl_easy *data,
221 struct SingleRequest *k)
223 struct connectdata *conn = data->conn;
224 CURLcode result = CURLE_OK;
225 char *buf, *xfer_buf;
226 size_t blen, xfer_blen;
227 int maxloops = 10;
228 bool is_multiplex = FALSE;
229 bool rcvd_eagain = FALSE;
230 bool is_eos = FALSE, rate_limited = FALSE;
232 result = Curl_multi_xfer_buf_borrow(data, &xfer_buf, &xfer_blen);
233 if(result)
234 goto out;
236 /* This is where we loop until we have read everything there is to
237 read or we get a CURLE_AGAIN */
238 do {
239 size_t bytestoread;
241 if(!is_multiplex) {
242 /* Multiplexed connection have inherent handling of EOF and we do not
243 * have to carefully restrict the amount we try to read.
244 * Multiplexed changes only in one direction. */
245 is_multiplex = Curl_conn_is_multiplex(conn, FIRSTSOCKET);
246 }
248 buf = xfer_buf;
249 bytestoread = xfer_blen;
251 if(bytestoread && Curl_rlimit_active(&data->progress.dl.rlimit)) {
252 curl_off_t dl_avail = Curl_rlimit_avail(&data->progress.dl.rlimit, NULL);
253#if 0
254 DEBUGF(infof(data, "dl_rlimit, available=%" FMT_OFF_T, dl_avail));
255#endif
256 /* In case of rate limited downloads: if this loop already got data and
257 * less than 16k is left in the limit, break out. We want to stutter a
258 * bit to keep in the limit, but too small receives will cost cpu
259 * unnecessarily. */
260 if(dl_avail <= 0) {
261 rate_limited = TRUE;
262 break;
263 }
264 if(dl_avail < (curl_off_t)bytestoread)
265 bytestoread = (size_t)dl_avail;
266 }
268 rcvd_eagain = FALSE;
269 result = xfer_recv_resp(data, buf, bytestoread, is_multiplex, &blen);
270 if(result) {
271 if(result != CURLE_AGAIN)
272 goto out; /* real error */
273 rcvd_eagain = TRUE;
274 result = CURLE_OK;
275 if(data->req.download_done && data->req.no_body &&
276 !data->req.resp_trailer) {
277 DEBUGF(infof(data, "EAGAIN, download done, no trailer announced, "
278 "not waiting for EOS"));
279 blen = 0;
280 /* continue as if we received the EOS */
281 }
282 else
283 break; /* get out of loop */
284 }
286 /* We only get a 0-length receive at the end of the response */
287 is_eos = (blen == 0);
289 if(!blen) {
290 result = Curl_req_stop_send_recv(data);
291 if(result)
292 goto out;
293 if(k->eos_written) /* already did write this to client, leave */
294 break;
295 }
297 result = Curl_xfer_write_resp(data, buf, blen, is_eos);
298 if(result || data->req.done)
299 goto out;
301 /* if we are done, we stop receiving. On multiplexed connections,
302 * we should read the EOS. Which may arrive as meta data after
303 * the bytes. Not taking it in might lead to RST of streams. */
304 if((!is_multiplex && data->req.download_done) || is_eos) {
305 CURL_REQ_CLEAR_RECV(data);
306 }
307 /* if we stopped receiving, leave the loop */
308 if(!CURL_REQ_WANT_RECV(data))
309 break;
311 } while(maxloops--);
313 if(!is_eos && !rate_limited && CURL_REQ_WANT_RECV(data) &&
314 (!rcvd_eagain || data_pending(data, rcvd_eagain))) {
315 /* Did not read until EAGAIN/EOS or there is still data pending
316 * in buffers. Mark as read-again via simulated SELECT results. */
317 Curl_multi_mark_dirty(data);
318 CURL_TRC_M(data, "sendrecv_dl() no EAGAIN/pending data, mark as dirty");
319 }
321 if(!CURL_REQ_WANT_RECV(data) && CURL_REQ_WANT_SEND(data) &&
322 (conn->bits.close || is_multiplex)) {
323 /* When we have read the entire thing and the close bit is set, the server
324 may now close the connection. If there is now any kind of sending going
325 on from our side, we need to stop that immediately. */
326 infof(data, "we are done reading and this is set to close, stop send");
327 Curl_req_abort_sending(data);
328 }
330out:
331 Curl_multi_xfer_buf_release(data, xfer_buf);
332 if(result)
333 DEBUGF(infof(data, "sendrecv_dl() -> %d", (int)result));
334 return result;
337/*
338 * Send data to upload to the server, when the socket is writable.
339 */
340static CURLcode sendrecv_ul(struct Curl_easy *data)
342 /* We should not get here when the sending is already done. */
343 DEBUGASSERT(!Curl_req_done_sending(data));
345 if(!Curl_req_done_sending(data))
346 return Curl_req_send_more(data);
347 return CURLE_OK;
350/*
351 * Curl_sendrecv() is the low-level function to be called when data is to
352 * be read and written to/from the connection.
353 */
354CURLcode Curl_sendrecv(struct Curl_easy *data)
356 struct SingleRequest *k = &data->req;
357 const struct curltime *pnow = NULL;
358 CURLcode result = CURLE_OK;
360 if(Curl_xfer_is_blocked(data)) {
361 result = CURLE_OK;
362 goto out;
363 }
365 /* We go ahead and do a read if we have a readable socket or if the stream
366 was rewound (in which case we have data in a buffer) */
367 if(CURL_REQ_WANT_RECV(data)) {
368 result = sendrecv_dl(data, k);
369 if(result || data->req.done)
370 goto out;
371 }
373 /* If we still have writing to do, we check if we have a writable socket. */
374 if(Curl_req_want_send(data)) {
375 result = sendrecv_ul(data);
376 if(result)
377 goto out;
378 }
380 pnow = Curl_pgrs_now(data);
381 if(CURL_REQ_WANT_IO(data)) {
382 if(Curl_timeleft_now_ms(data, pnow) < 0) {
383 if(k->size != -1) {
384 failf(data, "Operation timed out after %" FMT_TIMEDIFF_T
385 " milliseconds with %" FMT_OFF_T " out of %"
386 FMT_OFF_T " bytes received",
387 Curl_pgrs_since_ms(data, NULL, TIMER_STARTSINGLE),
388 k->bytecount, k->size);
389 }
390 else {
391 failf(data, "Operation timed out after %" FMT_TIMEDIFF_T
392 " milliseconds with %" FMT_OFF_T " bytes received",
393 Curl_pgrs_since_ms(data, NULL, TIMER_STARTSINGLE),
394 k->bytecount);
395 }
396 result = CURLE_OPERATION_TIMEDOUT;
397 goto out;
398 }
399 }
400 else {
401 /*
402 * The transfer has been performed. Make some general checks before
403 * returning.
404 */
405 if(!data->req.no_body && (k->size != -1) &&
406 (k->bytecount != k->size) && !k->newurl) {
407 failf(data, "transfer closed with %" FMT_OFF_T
408 " bytes remaining to read", k->size - k->bytecount);
409 result = CURLE_PARTIAL_FILE;
410 goto out;
411 }
412 }
414 /* If there is nothing more to send/recv, the request is done */
415 if(!CURL_REQ_WANT_IO(data))
416 data->req.done = TRUE;
418 result = Curl_pgrsCheckX(data, pnow);
420out:
421 if(result)
422 DEBUGF(infof(data, "Curl_sendrecv() -> %d", (int)result));
423 return result;
426/* Curl_init_CONNECT() gets called each time the handle switches to CONNECT
427 which means this gets called once for each subsequent redirect etc */
428void Curl_init_CONNECT(struct Curl_easy *data)
430 data->state.fread_func = data->set.fread_func_set;
431 data->state.in = data->set.in_set;
432 data->state.upload = (data->state.httpreq == HTTPREQ_PUT);
435/*
436 * Curl_pretransfer() is called immediately before a transfer starts, and only
437 * once for one transfer no matter if it has redirects or do multi-pass
438 * authentication etc.
439 */
440CURLcode Curl_pretransfer(struct Curl_easy *data)
442 CURLcode result = CURLE_OK;
444 /* Reset the retry count at the start of each request.
445 * If the retry count is not reset, when the connection drops,
446 * it will not enter the retry mechanism on CONN_MAX_RETRIES + 1 attempts
447 * and will immediately throw
448 * "Connection died, tried CONN_MAX_RETRIES times before giving up".
449 * By resetting it here, we ensure each new request starts fresh. */
450 data->state.retrycount = 0;
452 if(!CURL_EASY_STR(data, STRING_SET_URL) && !data->set.uh) {
453 /* we cannot do anything without URL */
454 failf(data, "No URL set");
455 return CURLE_URL_MALFORMAT;
456 }
458 /* CURLOPT_CURLU overrides CURLOPT_URL and the contents of the CURLU handle
459 is allowed to be changed by the user between transfers */
460 if(data->set.uh) {
461 char *url = NULL;
462 CURLUcode uc;
463 uc = curl_url_get(data->set.uh, CURLUPART_URL, &url, 0);
464 if(uc) {
465 /* clear the pointer to not point to freed memory anymore */
466 Curl_bufref_set(&data->state.url, NULL, 0, NULL);
467 failf(data, "No URL set");
468 return CURLE_URL_MALFORMAT;
469 }
470 result = CURL_EASY_STR_SETN(data, STRING_SET_URL, url);
471 if(result)
472 return result;
473 }
475 Curl_bufref_set(&data->state.url, CURL_EASY_STR(data, STRING_SET_URL),
476 0, NULL);
478 if(data->set.postfields && data->set.set_resume_from) {
479 /* we cannot */
480 failf(data, "cannot mix POSTFIELDS with RESUME_FROM");
481 return CURLE_BAD_FUNCTION_ARGUMENT;
482 }
484 data->state.prefer_ascii = data->set.prefer_ascii;
485#ifdef CURL_LIST_ONLY_PROTOCOL
486 data->state.list_only = data->set.list_only;
487#endif
488 data->state.httpreq = data->set.method;
490 /* initial transfer request coming up, forget the initial origin
491 * from a previous perform() on this handle. */
492 Curl_peer_unlink(&data->state.initial_origin);
493 Curl_peer_unlink(&data->state.origin);
494 data->state.requests = 0;
495 data->state.followlocation = 0; /* reset the location-follow counter */
496 data->state.this_is_a_follow = FALSE; /* reset this */
497 data->state.http_ignorecustom = FALSE; /* use custom HTTP method */
498 data->state.errorbuf = FALSE; /* no error has occurred */
499#ifndef CURL_DISABLE_HTTP
500 Curl_http_neg_init(data, &data->state.http_neg);
501#endif
502 data->state.authproblem = FALSE;
503 data->state.authhost.want = data->set.httpauth;
504 data->state.authproxy.want = data->set.proxyauth;
505 curlx_safefree(data->info.wouldredirect);
506 curlx_safefree(data->info.effective_url);
507 Curl_data_priority_clear_state(data);
508 if(data->set.http_auto_referer)
509 Curl_bufref_free(&data->state.referer);
510 if(CURL_EASY_STR(data, STRING_SET_REFERER))
511 Curl_bufref_set(&data->state.referer,
512 CURL_EASY_STR(data, STRING_SET_REFERER), 0, NULL);
513 else
514 Curl_bufref_free(&data->state.referer);
516 if(data->state.httpreq == HTTPREQ_PUT)
517 data->state.infilesize = data->set.filesize;
518 else if((data->state.httpreq != HTTPREQ_GET) &&
519 (data->state.httpreq != HTTPREQ_HEAD)) {
520 data->state.infilesize = data->set.postfieldsize;
521 if(data->set.postfields && (data->state.infilesize == -1))
522 data->state.infilesize = (curl_off_t)strlen(data->set.postfields);
523 }
524 else
525 data->state.infilesize = 0;
527 /* If there is a list of cookie files to read, do it now! */
528 result = Curl_cookie_loadfiles(data,
529 data->set.cookiesession ?
530 COOKIE_NOSESSION : 0);
531 if(!result)
532 Curl_cookie_run(data); /* activate */
534 /* If there is a list of host pairs to deal with */
535 if(!result && data->state.resolve)
536 result = Curl_loadhostpairs(data);
538 if(!result)
539 /* If there is a list of hsts files to read */
540 result = Curl_hsts_loadfiles(data);
542 if(!result) {
543 /* Allow data->set.use_port to set which port to use. This needs to be
544 * disabled for example when we follow Location: headers to URLs using
545 * different ports! */
546 data->state.allow_port = TRUE;
548#if defined(HAVE_SIGNAL) && defined(SIGPIPE) && !defined(MSG_NOSIGNAL)
549 /*************************************************************
550 * Tell signal handler to ignore SIGPIPE
551 *************************************************************/
552 if(!data->set.no_signal)
553 data->state.prev_signal = signal(SIGPIPE, SIG_IGN);
554#endif
556 Curl_initinfo(data); /* reset session-specific information "variables" */
557 Curl_pgrsResetTransferSizes(data);
558 Curl_pgrsStart(data, NULL);
560 /* In case the handle is reused and an authentication method was picked
561 in the session we need to make sure we only use the one(s) we now
562 consider to be fine */
563 data->state.authhost.picked &= data->state.authhost.want;
564 data->state.authproxy.picked &= data->state.authproxy.want;
566#ifndef CURL_DISABLE_FTP
567 data->state.wildcardmatch = data->set.wildcard_enabled;
568#ifdef DEBUGBUILD
569 if(getenv("CURL_DBG_FTP_WILDCARD"))
570 data->state.wildcardmatch = TRUE;
571#endif
572 if(data->state.wildcardmatch) {
573 struct WildcardData *wc;
574 if(!data->wildcard) {
575 data->wildcard = curlx_calloc(1, sizeof(struct WildcardData));
576 if(!data->wildcard)
577 return CURLE_OUT_OF_MEMORY;
578 }
579 wc = data->wildcard;
580 if(wc->state < CURLWC_INIT) {
581 if(wc->ftpwc)
582 wc->dtor(wc->ftpwc);
583 curlx_safefree(wc->pattern);
584 curlx_safefree(wc->path);
585 Curl_wildcard_init(wc); /* init wildcard structures */
586 }
587 }
588#endif
589 result = Curl_hsts_loadcb(data, data->hsts);
590 }
592 data->req.headerbytecount = 0;
593 /* a previous transfer on this handle may have ended with a rewind request
594 * still pending (a follow or auth retry that failed). This is a new
595 * transfer, so drop those readers now instead of letting a later upload
596 * read from them. */
597 data->req.rewind_read = FALSE;
598 Curl_client_reset(data);
599 Curl_headers_cleanup(data);
600 return result;
603/* Returns CURLE_OK *and* sets '*url' if a request retry is wanted.
605 NOTE: that the *url is curlx_malloc()ed. */
606CURLcode Curl_retry_request(struct Curl_easy *data, char **url)
608 struct connectdata *conn = data->conn;
609 bool retry = FALSE;
610 *url = NULL;
612 /* if we are talking upload, we cannot do the checks below, unless the
613 protocol is HTTP as when uploading over HTTP we will still get a
614 response */
615 if(data->state.upload &&
616 !(conn->scheme->protocol & (PROTO_FAMILY_HTTP | CURLPROTO_RTSP)))
617 return CURLE_OK;
619 if(conn->bits.reuse &&
620 (data->req.bytecount + data->req.headerbytecount == 0) &&
621 ((!data->req.no_body && !data->req.done) ||
622 (conn->scheme->protocol & PROTO_FAMILY_HTTP))
623#ifndef CURL_DISABLE_RTSP
624 && (data->set.rtspreq != RTSPREQ_RECEIVE)
625#endif
626 )
627 /* We got no data, we attempted to reuse a connection. For HTTP this
628 can be a retry so we try again regardless if we expected a body.
629 For other protocols we only try again only if we expected a body.
631 This might happen if the connection was left alive when we were
632 done using it before, but that was closed when we wanted to read from
633 it again. Bad luck. Retry the same request on a fresh connect! */
634 retry = TRUE;
635 else if(data->state.refused_stream &&
636 (data->req.bytecount + data->req.headerbytecount == 0)) {
637 /* This was sent on a refused stream, safe to rerun. A refused stream
638 error can typically only happen on HTTP/2 level if the stream is safe
639 to issue again, but the nghttp2 API can deliver the message to other
640 streams as well, which is why this adds the check the data counters
641 too. */
642 infof(data, "REFUSED_STREAM, retrying a fresh connect");
643 data->state.refused_stream = FALSE; /* clear again */
644 retry = TRUE;
645 }
646 if(retry) {
647#define CONN_MAX_RETRIES 5
648 if(data->state.retrycount++ >= CONN_MAX_RETRIES) {
649 failf(data, "Connection died, tried %d times before giving up",
650 CONN_MAX_RETRIES);
651 data->state.retrycount = 0;
652 return CURLE_SEND_ERROR;
653 }
654 infof(data, "Connection died, retrying a fresh connect (retry count: %d)",
655 data->state.retrycount);
656 *url = Curl_bufref_dup(&data->state.url);
657 if(!*url)
658 return CURLE_OUT_OF_MEMORY;
660 connclose(conn); /* close this connection */
661 conn->bits.retry = TRUE; /* mark this as a connection we are about to
662 retry. Marking it this way should prevent i.e
663 HTTP transfers to return error because nothing
664 has been transferred! */
665 Curl_creader_set_rewind(data, TRUE);
666 }
667 return CURLE_OK;
670static void xfer_setup(
671 struct Curl_easy *data, /* transfer */
672 int8_t send_idx, /* sockindex to send on or -1 */
673 int8_t recv_idx, /* sockindex to receive on or -1 */
674 curl_off_t recv_size /* how much to receive, -1 if unknown */
675 )
677 struct SingleRequest *k = &data->req;
678 struct connectdata *conn = data->conn;
680 DEBUGASSERT(conn);
681 /* indexes are in range */
682 DEBUGASSERT((send_idx <= 1) && (send_idx >= -1));
683 DEBUGASSERT((recv_idx <= 1) && (recv_idx >= -1));
684 /* if request wants to send, switching off the send direction is wrong */
685 DEBUGASSERT((send_idx >= 0) || !Curl_req_want_send(data));
687 conn->send_idx = send_idx;
688 conn->recv_idx = recv_idx;
690 /* without receiving, there should be not recv_size */
691 DEBUGASSERT((conn->recv_idx >= 0) || (recv_size == -1));
692 k->size = recv_size;
693 k->header = !!conn->scheme->run->write_resp_hd;
694 /* by default, we do not shutdown at the end of the transfer */
695 k->shutdown = FALSE;
696 k->shutdown_err_ignore = FALSE;
698 /* The code sequence below is placed in this function because all necessary
699 input is not always known in do_complete() as this function may be called
700 after that */
701 if(!k->header && (recv_size > 0))
702 Curl_pgrsSetDownloadSize(data, recv_size);
704 /* we want header and/or body, if neither then do not do this! */
705 if(conn->scheme->run->write_resp_hd || !data->req.no_body) {
706 if(conn->recv_idx != -1)
707 CURL_REQ_SET_RECV(data);
708 if(conn->send_idx != -1)
709 CURL_REQ_SET_SEND(data);
710 }
711 CURL_TRC_M(data, "xfer_setup: recv_idx=%d, send_idx=%d",
712 conn->recv_idx, conn->send_idx);
715void Curl_xfer_setup_nop(struct Curl_easy *data)
717 xfer_setup(data, -1, -1, -1);
720void Curl_xfer_setup_sendrecv(struct Curl_easy *data,
721 int8_t sockindex,
722 curl_off_t recv_size)
724 xfer_setup(data, sockindex, sockindex, recv_size);
727void Curl_xfer_setup_send(struct Curl_easy *data,
728 int8_t sockindex)
730 xfer_setup(data, sockindex, -1, -1);
733void Curl_xfer_setup_recv(struct Curl_easy *data,
734 int8_t sockindex,
735 curl_off_t recv_size)
737 xfer_setup(data, -1, sockindex, recv_size);
740void Curl_xfer_set_shutdown(struct Curl_easy *data,
741 bool shutdown,
742 bool ignore_errors)
744 /* Shutdown should only be set when the transfer only sends or receives. */
745 DEBUGASSERT(!shutdown ||
746 (data->conn->send_idx < 0) || (data->conn->recv_idx < 0));
747 data->req.shutdown = shutdown;
748 data->req.shutdown_err_ignore = ignore_errors;
751CURLcode Curl_xfer_write_resp(struct Curl_easy *data,
752 const char *buf, size_t blen,
753 bool is_eos)
755 CURLcode result = CURLE_OK;
757 if(data->conn->scheme->run->write_resp) {
758 /* protocol handlers offering this function take full responsibility
759 * for writing all received download data to the client. */
760 result = data->conn->scheme->run->write_resp(data, buf, blen, is_eos);
761 }
762 else {
763 /* No special handling by protocol handler, write all received data
764 * as BODY to the client. */
765 if(blen || is_eos) {
766 int cwtype = CLIENTWRITE_BODY;
767 if(is_eos)
768 cwtype |= CLIENTWRITE_EOS;
769 result = Curl_client_write(data, cwtype, buf, blen);
770 }
771 }
773 if(!result && is_eos) {
774 /* If we wrote the EOS, we are definitely done */
775 data->req.eos_written = TRUE;
776 data->req.download_done = TRUE;
777 }
778 CURL_TRC_WRITE(data, "xfer_write_resp(len=%zu, eos=%d) -> %d",
779 blen, is_eos, (int)result);
780 return result;
783bool Curl_xfer_write_is_paused(struct Curl_easy *data)
785 return Curl_cwriter_is_paused(data);
788CURLcode Curl_xfer_write_resp_hd(struct Curl_easy *data,
789 const char *hd0, size_t hdlen, bool is_eos)
791 if(data->conn->scheme->run->write_resp_hd) {
792 DEBUGASSERT(!hd0[hdlen]); /* null-terminated */
793 /* protocol handlers offering this function take full responsibility
794 * for writing all received download data to the client. */
795 return data->conn->scheme->run->write_resp_hd(data, hd0, hdlen, is_eos);
796 }
797 /* No special handling by protocol handler, write as response bytes */
798 return Curl_xfer_write_resp(data, hd0, hdlen, is_eos);
801CURLcode Curl_xfer_write_done(struct Curl_easy *data, bool premature)
803 (void)premature;
804 return Curl_cw_out_done(data);
807bool Curl_xfer_needs_flush(struct Curl_easy *data)
809 return Curl_conn_needs_flush(data, data->conn->send_idx);
812CURLcode Curl_xfer_flush(struct Curl_easy *data)
814 return Curl_conn_flush(data, data->conn->send_idx);
817CURLcode Curl_xfer_send(struct Curl_easy *data,
818 const void *buf, size_t blen, bool eos,
819 size_t *pnwritten)
821 CURLcode result;
823 DEBUGASSERT(data);
824 DEBUGASSERT(data->conn);
826 result = Curl_conn_send(data, data->conn->send_idx,
827 buf, blen, eos, pnwritten);
828 if(result == CURLE_AGAIN) {
829 result = CURLE_OK;
830 *pnwritten = 0;
831 }
832 else if(!result && *pnwritten)
833 data->info.request_size += *pnwritten;
835 DEBUGF(infof(data, "Curl_xfer_send(len=%zu, eos=%d) -> %d, %zu",
836 blen, eos, (int)result, *pnwritten));
837 return result;
840CURLcode Curl_xfer_recv(struct Curl_easy *data,
841 char *buf, size_t blen,
842 size_t *pnrcvd)
844 DEBUGASSERT(data);
845 DEBUGASSERT(data->conn);
846 DEBUGASSERT(data->set.buffer_size > 0);
848 if(curlx_uitouz(data->set.buffer_size) < blen)
849 blen = curlx_uitouz(data->set.buffer_size);
850 return Curl_conn_recv(data, data->conn->recv_idx, buf, blen, pnrcvd);
853CURLcode Curl_xfer_send_close(struct Curl_easy *data)
855 Curl_conn_ev_data_done_send(data);
856 return CURLE_OK;
859bool Curl_xfer_is_blocked(struct Curl_easy *data)
861 bool want_send = CURL_REQ_WANT_SEND(data);
862 bool want_recv = CURL_REQ_WANT_RECV(data);
863 if(!want_send)
864 return want_recv && Curl_xfer_recv_is_paused(data);
865 else if(!want_recv)
866 return want_send && Curl_xfer_send_is_paused(data);
867 else
868 return Curl_xfer_recv_is_paused(data) && Curl_xfer_send_is_paused(data);
871bool Curl_xfer_send_is_paused(struct Curl_easy *data)
873 return Curl_rlimit_is_blocked(&data->progress.ul.rlimit);
876bool Curl_xfer_recv_is_paused(struct Curl_easy *data)
878 return Curl_rlimit_is_blocked(&data->progress.dl.rlimit);
881CURLcode Curl_xfer_pause_send(struct Curl_easy *data, bool enable)
883 CURLcode result = CURLE_OK;
884 Curl_rlimit_block(&data->progress.ul.rlimit, enable, Curl_pgrs_now(data));
885 if(!enable && Curl_creader_is_paused(data))
886 result = Curl_creader_unpause(data);
887 Curl_pgrsSendPause(data, enable);
888 return result;
891CURLcode Curl_xfer_pause_recv(struct Curl_easy *data, bool enable)
893 CURLcode result = CURLE_OK;
894 Curl_rlimit_block(&data->progress.dl.rlimit, enable, Curl_pgrs_now(data));
895 if(!enable && Curl_cwriter_is_paused(data))
896 result = Curl_cwriter_unpause(data);
897 Curl_conn_ev_data_pause(data, enable);
898 Curl_pgrsRecvPause(data, enable);
899 return result;
902bool Curl_xfer_is_secure(struct Curl_easy *data)
904#ifndef CURL_DISABLE_PROXY
905 if(data->conn && data->conn->bits.origin_is_proxy) {
906 /* talking to a forward proxy, not secure. we do not use
907 * a forward proxy for https: and other 's' URLs. Let's just check that
908 * this did not fail somewhere. */
909 DEBUGASSERT(!(data->state.origin->scheme->flags & PROTOPT_SSL));
910 return FALSE;
911 }
912#endif
913 return (data->state.origin->scheme->flags & PROTOPT_SSL);
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2009.6 KiB · hit25 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=25
git.response.bytes=9829
git.response.cache=HIT
git.response.duration_ms=25
git.fetch.wants=abc7623f233b44b745d1f56bbb6851deee0760ac
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=9829
git.pkt.payload.max=9808
git.sideband.band1.bytes=9807
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
a5e24d640be40ecd
Request
affad1ea…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format