master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#ifdef HAVE_NETINET_IN_H
27#include <netinet/in.h>
28#endif
30#include "urldata.h"
31#include "sendf.h"
32#include "curl_trc.h"
33#include "transfer.h"
34#include "cfilters.h"
35#include "connect.h"
36#include "cw-out.h"
37#include "cw-pause.h"
38#include "multiif.h"
39#include "progress.h"
41static void cl_reset_writer(struct Curl_easy *data)
42{
43 struct Curl_cwriter *writer = data->req.writer.stack;
44 while(writer) {
45 data->req.writer.stack = writer->next;
46 writer->cwt->do_close(data, writer);
47 curlx_free(writer);
48 writer = data->req.writer.stack;
49 }
50 data->req.writer.paused = FALSE;
51}
53static void cl_reset_reader(struct Curl_easy *data)
54{
55 struct Curl_creader *reader = data->req.reader.stack;
56 data->req.reader_started = FALSE;
57 while(reader) {
58 data->req.reader.stack = reader->next;
59 reader->crt->do_close(data, reader);
60 curlx_free(reader);
61 reader = data->req.reader.stack;
62 }
63}
65void Curl_client_cleanup(struct Curl_easy *data)
66{
67 cl_reset_reader(data);
68 cl_reset_writer(data);
70 data->req.bytecount = 0;
71 data->req.headerline = 0;
72}
74void Curl_client_reset(struct Curl_easy *data)
75{
76 if(data->req.rewind_read) {
77 /* already requested */
78 CURL_TRC_READ(data, "client_reset, will rewind reader");
79 }
80 else {
81 CURL_TRC_READ(data, "client_reset, clear readers");
82 cl_reset_reader(data);
83 }
84 cl_reset_writer(data);
86 data->req.bytecount = 0;
87 data->req.headerline = 0;
88}
90CURLcode Curl_client_start(struct Curl_easy *data)
91{
92 if(data->req.rewind_read) {
93 struct Curl_creader *r = data->req.reader.stack;
94 CURLcode result = CURLE_OK;
96 CURL_TRC_READ(data, "client start, rewind readers");
97 while(r) {
98 result = r->crt->cntrl(data, r, CURL_CRCNTRL_REWIND);
99 if(result) {
100 failf(data, "rewind of client reader '%s' failed: %d",
101 r->crt->name, (int)result);
102 return result;
103 }
104 r = r->next;
105 }
106 data->req.rewind_read = FALSE;
107 cl_reset_reader(data);
108 }
109 return CURLE_OK;
110}
112bool Curl_creader_will_rewind(struct Curl_easy *data)
113{
114 return (bool)data->req.rewind_read;
115}
117void Curl_creader_set_rewind(struct Curl_easy *data, bool enable)
118{
119 data->req.rewind_read = !!enable;
120}
122CURLcode Curl_cwriter_def_init(struct Curl_easy *data,
123 struct Curl_cwriter *writer)
124{
125 (void)data;
126 (void)writer;
127 return CURLE_OK;
128}
130CURLcode Curl_cwriter_def_write(struct Curl_easy *data,
131 struct Curl_cwriter *writer, int type,
132 const char *buf, size_t nbytes)
133{
134 return Curl_cwriter_write(data, writer->next, type, buf, nbytes);
135}
137CURLcode Curl_cwriter_def_flush(struct Curl_easy *data,
138 struct Curl_cwriter *writer, bool eos)
139{
140 return Curl_cwriter_flush(data, writer->next, eos);
141}
143void Curl_cwriter_def_close(struct Curl_easy *data,
144 struct Curl_cwriter *writer)
145{
146 (void)data;
147 (void)writer;
148}
150static size_t get_max_body_write_len(struct Curl_easy *data, curl_off_t limit)
151{
152 if(limit != -1) {
153 /* How much more are we allowed to write? */
154 return curlx_sotouz_range(limit - data->req.bytecount, 0, SIZE_MAX);
155 }
156 return SIZE_MAX;
157}
159struct cw_download_ctx {
160 struct Curl_cwriter super;
161 BIT(started_response);
162 BIT(started_body);
163};
165/* Download client writer in phase CURL_CW_PROTOCOL that
166 * sees the "real" download body data. */
167static CURLcode cw_download_write(struct Curl_easy *data,
168 struct Curl_cwriter *writer, int type,
169 const char *buf, size_t nbytes)
170{
171 struct cw_download_ctx *ctx = writer->ctx;
172 CURLcode result;
173 size_t nwrite, excess_len = 0;
174 bool is_connect = !!(type & CLIENTWRITE_CONNECT);
176 if(!ctx->started_response &&
177 !(type & CLIENTWRITE_CONNECT) &&
178 (!(type & CLIENTWRITE_INFO) || data->req.upload_done)) {
179 Curl_pgrsTime(data, TIMER_STARTTRANSFER);
180 ctx->started_response = TRUE;
181 }
183 if(!(type & CLIENTWRITE_BODY)) {
184 if(is_connect && data->set.suppress_connect_headers)
185 return CURLE_OK;
186#ifdef DEBUGBUILD
187 if(is_connect && getenv("CURL_DBG_SUPPRESS_CONNECT_HDS"))
188 return CURLE_OK;
189#endif
190 result = Curl_cwriter_write(data, writer->next, type, buf, nbytes);
191 CURL_TRC_WRITE(data, "download_write header(type=%x, blen=%zu) -> %d",
192 (unsigned int)type, nbytes, (int)result);
193 return result;
194 }
196 if(!ctx->started_body &&
197 !(type & (CLIENTWRITE_INFO | CLIENTWRITE_CONNECT))) {
198 Curl_rlimit_start(&data->progress.dl.rlimit, Curl_pgrs_now(data),
199 data->req.size);
200 ctx->started_body = TRUE;
201 }
203 /* Here, we deal with REAL BODY bytes. All filtering and transfer
204 * encodings have been applied and only the true content, e.g. BODY,
205 * bytes are passed here.
206 * This allows us to check sizes, update stats, etc. independent
207 * from the protocol in play. */
209 if(data->req.no_body && nbytes > 0) {
210 /* BODY arrives although we want none, bail out */
211 streamclose(data->conn);
212 CURL_TRC_WRITE(data, "download_write body(type=%x, blen=%zu), "
213 "did not want a BODY", (unsigned int)type, nbytes);
214 data->req.download_done = TRUE;
215 if(data->info.header_size)
216 /* if headers have been received, this is fine */
217 return CURLE_OK;
218 return CURLE_WEIRD_SERVER_REPLY;
219 }
221 /* Determine if we see any bytes in excess to what is allowed.
222 * We write the allowed bytes and handle excess further below.
223 * This gives deterministic BODY writes on varying buffer receive
224 * lengths. */
225 nwrite = nbytes;
226 if(data->req.maxdownload != -1) {
227 size_t wmax = get_max_body_write_len(data, data->req.maxdownload);
228 if(nwrite > wmax) {
229 excess_len = nbytes - wmax;
230 nwrite = wmax;
231 }
233 if(nwrite == wmax) {
234 data->req.download_done = TRUE;
235 }
237 if((type & CLIENTWRITE_EOS) && !data->req.no_body &&
238 (data->req.size > data->req.bytecount)) {
239 failf(data, "end of response with %" FMT_OFF_T " bytes missing",
240 data->req.size - data->req.bytecount);
241 return CURLE_PARTIAL_FILE;
242 }
243 }
245 /* Error on too large filesize is handled below, after writing
246 * the permitted bytes */
247 if(data->set.max_filesize && !data->req.ignorebody) {
248 size_t wmax = get_max_body_write_len(data, data->set.max_filesize);
249 if(nwrite > wmax) {
250 nwrite = wmax;
251 }
252 }
254 if(!data->req.ignorebody && (nwrite || (type & CLIENTWRITE_EOS))) {
255 result = Curl_cwriter_write(data, writer->next, type, buf, nwrite);
256 CURL_TRC_WRITE(data, "download_write body(type=%x, blen=%zu) -> %d",
257 (unsigned int)type, nbytes, (int)result);
258 if(result)
259 return result;
260 }
262 /* Update stats, write and report progress */
263 if(nwrite) {
264 data->req.bytecount += nwrite;
265 Curl_pgrs_download_inc(data, nwrite);
266 }
268 if(excess_len) {
269 if(!data->req.ignorebody) {
270 infof(data,
271 "Excess found writing body:"
272 " excess = %zu"
273 ", size = %" FMT_OFF_T
274 ", maxdownload = %" FMT_OFF_T
275 ", bytecount = %" FMT_OFF_T,
276 excess_len, data->req.size, data->req.maxdownload,
277 data->req.bytecount);
278 connclose(data->conn);
279 }
280 }
281 else if((nwrite < nbytes) && !data->req.ignorebody) {
282 failf(data, "Exceeded the maximum allowed file size "
283 "(%" FMT_OFF_T ") with %" FMT_OFF_T " bytes",
284 data->set.max_filesize, data->req.bytecount);
285 return CURLE_FILESIZE_EXCEEDED;
286 }
288 return CURLE_OK;
289}
291static const struct Curl_cwtype cw_download = {
292 "protocol",
293 NULL,
294 0,
295 Curl_cwriter_def_init,
296 cw_download_write,
297 Curl_cwriter_def_flush,
298 Curl_cwriter_def_close,
299 sizeof(struct cw_download_ctx)
300};
302/* RAW client writer in phase CURL_CW_RAW that
303 * enabled tracing of raw data. */
304static CURLcode cw_raw_write(struct Curl_easy *data,
305 struct Curl_cwriter *writer, int type,
306 const char *buf, size_t nbytes)
307{
308 if(type & CLIENTWRITE_BODY && data->set.verbose && !data->req.ignorebody) {
309 Curl_debug(data, CURLINFO_DATA_IN, buf, nbytes);
310 }
311 return Curl_cwriter_write(data, writer->next, type, buf, nbytes);
312}
314static const struct Curl_cwtype cw_raw = {
315 "raw",
316 NULL,
317 0,
318 Curl_cwriter_def_init,
319 cw_raw_write,
320 Curl_cwriter_def_flush,
321 Curl_cwriter_def_close,
322 sizeof(struct Curl_cwriter)
323};
325static void cwriter_add(struct Curl_easy *data,
326 struct Curl_cwriter *writer)
327{
328 struct Curl_cwriter **anchor = &data->req.writer.stack;
330 /* Insert the writer as first in its phase.
331 * Skip existing writers of lower phases. */
332 while(*anchor && (*anchor)->phase < writer->phase)
333 anchor = &(*anchor)->next;
334 writer->next = *anchor;
335 *anchor = writer;
336}
338static CURLcode do_init_writer_stack(struct Curl_easy *data)
339{
340 struct Curl_cwriter *writer;
341 CURLcode result;
343 DEBUGASSERT(!data->req.writer.stack);
344 result = Curl_cwriter_create(&data->req.writer.stack,
345 data, &Curl_cwt_out, CURL_CW_CLIENT);
346 if(result)
347 return result;
349 result = Curl_cwriter_create(&writer, data, &cw_download, CURL_CW_PROTOCOL);
350 if(result)
351 return result;
352 cwriter_add(data, writer);
354 result = Curl_cwriter_create(&writer, data, &cw_raw, CURL_CW_RAW);
355 if(result)
356 return result;
357 cwriter_add(data, writer);
359 return result;
360}
362/* Curl_client_write() sends data to the write callback(s)
364 The bit pattern defines to what "streams" to write to. Body and/or header.
365 The defines are in sendf.h of course.
366 */
367CURLcode Curl_client_write(struct Curl_easy *data, int type, const char *buf,
368 size_t len)
369{
370 CURLcode result;
372 /* it is one of those, at least */
373 DEBUGASSERT(type &
374 (CLIENTWRITE_BODY | CLIENTWRITE_HEADER | CLIENTWRITE_INFO));
375 /* BODY is only BODY (with optional EOS) */
376 DEBUGASSERT(!(type & CLIENTWRITE_BODY) ||
377 ((type & ~(CLIENTWRITE_BODY | CLIENTWRITE_EOS)) == 0));
378 /* INFO is only INFO (with optional EOS) */
379 DEBUGASSERT(!(type & CLIENTWRITE_INFO) ||
380 ((type & ~(CLIENTWRITE_INFO | CLIENTWRITE_EOS)) == 0));
382 if(!data->req.writer.stack) {
383 result = do_init_writer_stack(data);
384 if(result)
385 return result;
386 DEBUGASSERT(data->req.writer.stack);
387 }
389 result = Curl_cwriter_write(data, data->req.writer.stack, type, buf, len);
390 CURL_TRC_WRITE(data, "client_write(type=%x, len=%zu) -> %d",
391 (unsigned int)type, len, (int)result);
392 return result;
393}
395CURLcode Curl_client_flush(struct Curl_easy *data, bool eos)
396{
397 CURLcode result;
399 if(!data->req.writer.stack) {
400 result = do_init_writer_stack(data);
401 if(result)
402 return result;
403 DEBUGASSERT(data->req.writer.stack);
404 }
406 result = Curl_cwriter_flush(data, data->req.writer.stack, eos);
407 CURL_TRC_WRITE(data, "client_flush(eos=%d) -> %d", eos, (int)result);
408 return result;
409}
411/* Create an unencoding writer stage using the given handler. */
412CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter,
413 struct Curl_easy *data,
414 const struct Curl_cwtype *cwt,
415 Curl_cwriter_phase phase)
416{
417 struct Curl_cwriter *writer = NULL;
418 CURLcode result = CURLE_OUT_OF_MEMORY;
419 void *p;
421 DEBUGASSERT(cwt->cwriter_size >= sizeof(struct Curl_cwriter));
422 p = curlx_calloc(1, cwt->cwriter_size);
423 if(!p)
424 goto out;
426 writer = (struct Curl_cwriter *)p;
427 writer->cwt = cwt;
428 writer->ctx = p;
429 writer->phase = phase;
430 result = cwt->do_init(data, writer);
432out:
433 *pwriter = result ? NULL : writer;
434 if(result)
435 curlx_free(writer);
436 return result;
437}
439void Curl_cwriter_free(struct Curl_easy *data,
440 struct Curl_cwriter *writer)
441{
442 if(writer) {
443 writer->cwt->do_close(data, writer);
444 curlx_free(writer);
445 }
446}
448size_t Curl_cwriter_count(struct Curl_easy *data, Curl_cwriter_phase phase)
449{
450 struct Curl_cwriter *w;
451 size_t n = 0;
453 for(w = data->req.writer.stack; w; w = w->next) {
454 if(w->phase == phase)
455 ++n;
456 }
457 return n;
458}
460static CURLcode cwriter_ensure_pause_writer(struct Curl_easy *data)
461{
462 struct Curl_cwriter *writer =
463 Curl_cwriter_get_by_type(data, &Curl_cwt_pause);
464 CURLcode result = CURLE_OK;
466 if(!writer) {
467 result = Curl_cwriter_create(&writer, data, &Curl_cwt_pause,
468 CURL_CW_BEFORE_DECODE);
469 if(!result)
470 cwriter_add(data, writer);
471 }
472 return result;
473}
475CURLcode Curl_cwriter_add(struct Curl_easy *data,
476 struct Curl_cwriter *writer)
477{
478 CURLcode result;
479 struct Curl_cwriter **anchor = &data->req.writer.stack;
481 if(!*anchor) {
482 result = do_init_writer_stack(data);
483 if(result)
484 return result;
485 }
487 if(writer->cwt->flags & CURL_CW_FLAG_BLOWUP) {
488 /* On adding a writer that may blow up write sizes, e.g. zip bombs,
489 * add the pause writer. Do this first as any failure will make the
490 * caller destroy the writer again. */
491 result = cwriter_ensure_pause_writer(data);
492 if(result)
493 return result;
494 }
496 cwriter_add(data, writer);
497 return CURLE_OK;
498}
500struct Curl_cwriter *Curl_cwriter_get_by_name(struct Curl_easy *data,
501 const char *name)
502{
503 struct Curl_cwriter *writer;
504 for(writer = data->req.writer.stack; writer; writer = writer->next) {
505 if(!strcmp(name, writer->cwt->name))
506 return writer;
507 }
508 return NULL;
509}
511struct Curl_cwriter *Curl_cwriter_get_by_type(struct Curl_easy *data,
512 const struct Curl_cwtype *cwt)
513{
514 struct Curl_cwriter *writer;
515 for(writer = data->req.writer.stack; writer; writer = writer->next) {
516 if(writer->cwt == cwt)
517 return writer;
518 }
519 return NULL;
520}
522CURLcode Curl_cwriter_unpause(struct Curl_easy *data)
523{
524 data->req.writer.paused = FALSE;
525 return Curl_cwriter_flush(data, data->req.writer.stack, FALSE);
526}
528CURLcode Curl_creader_read(struct Curl_easy *data,
529 struct Curl_creader *reader,
530 char *buf, size_t blen, size_t *nread, bool *eos)
531{
532 *nread = 0;
533 *eos = FALSE;
534 if(!reader)
535 return CURLE_READ_ERROR;
536 return reader->crt->do_read(data, reader, buf, blen, nread, eos);
537}
539void Curl_creader_clear_eos(struct Curl_easy *data,
540 struct Curl_creader *reader)
541{
542 while(reader) {
543 (void)reader->crt->cntrl(data, reader, CURL_CRCNTRL_CLEAR_EOS);
544 reader = reader->next;
545 }
546}
548CURLcode Curl_creader_def_init(struct Curl_easy *data,
549 struct Curl_creader *reader)
550{
551 (void)data;
552 (void)reader;
553 return CURLE_OK;
554}
556void Curl_creader_def_close(struct Curl_easy *data,
557 struct Curl_creader *reader)
558{
559 (void)data;
560 (void)reader;
561}
563CURLcode Curl_creader_def_read(struct Curl_easy *data,
564 struct Curl_creader *reader,
565 char *buf, size_t blen,
566 size_t *nread, bool *eos)
567{
568 if(reader->next)
569 return reader->next->crt->do_read(data, reader->next, buf, blen,
570 nread, eos);
571 else {
572 *nread = 0;
573 *eos = FALSE;
574 return CURLE_READ_ERROR;
575 }
576}
578bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
579 struct Curl_creader *reader)
580{
581 (void)data;
582 (void)reader;
583 return FALSE;
584}
586curl_off_t Curl_creader_def_total_length(struct Curl_easy *data,
587 struct Curl_creader *reader)
588{
589 return reader->next ?
590 reader->next->crt->total_length(data, reader->next) : -1;
591}
593CURLcode Curl_creader_def_resume_from(struct Curl_easy *data,
594 struct Curl_creader *reader,
595 curl_off_t offset)
596{
597 (void)data;
598 (void)reader;
599 (void)offset;
600 return CURLE_READ_ERROR;
601}
603CURLcode Curl_creader_def_cntrl(struct Curl_easy *data,
604 struct Curl_creader *reader,
605 Curl_creader_cntrl opcode)
606{
607 (void)data;
608 (void)reader;
609 (void)opcode;
610 return CURLE_OK;
611}
613bool Curl_creader_def_is_paused(struct Curl_easy *data,
614 struct Curl_creader *reader)
615{
616 (void)data;
617 (void)reader;
618 return FALSE;
619}
621void Curl_creader_def_done(struct Curl_easy *data,
622 struct Curl_creader *reader, int premature)
623{
624 (void)data;
625 (void)reader;
626 (void)premature;
627}
629struct cr_in_ctx {
630 struct Curl_creader super;
631 curl_read_callback read_cb;
632 void *cb_user_data;
633 curl_off_t total_len;
634 curl_off_t read_len;
635 CURLcode error_result;
636 BIT(seen_eos);
637 BIT(errored);
638 BIT(has_used_cb);
639 BIT(is_paused);
640};
642static CURLcode cr_in_init(struct Curl_easy *data, struct Curl_creader *reader)
643{
644 struct cr_in_ctx *ctx = reader->ctx;
645 ctx->read_cb = data->state.fread_func;
646 ctx->cb_user_data = data->state.in;
647 ctx->total_len = -1;
648 ctx->read_len = 0;
649 return CURLE_OK;
650}
652/* Real client reader to installed client callbacks. */
653static CURLcode cr_in_read(struct Curl_easy *data,
654 struct Curl_creader *reader,
655 char *buf, size_t blen,
656 size_t *pnread, bool *peos)
657{
658 struct cr_in_ctx *ctx = reader->ctx;
659 CURLcode result = CURLE_OK;
660 size_t nread;
662 ctx->is_paused = FALSE;
664 /* Once we have errored, we will return the same error forever */
665 if(ctx->errored) {
666 *pnread = 0;
667 *peos = FALSE;
668 return ctx->error_result;
669 }
670 if(ctx->seen_eos) {
671 *pnread = 0;
672 *peos = TRUE;
673 return CURLE_OK;
674 }
675 /* respect length limitations */
676 if(ctx->total_len >= 0) {
677 blen = curlx_sotouz_range(ctx->total_len - ctx->read_len, 0, blen);
678 }
679 nread = 0;
680 if(ctx->read_cb && blen) {
681 struct Curl_mapi_guard guard;
682 CURL_CBAPI_START(&guard, data, easy_cr_in_read);
683 nread = ctx->read_cb(buf, 1, blen, ctx->cb_user_data);
684 CURL_CBAPI_END(&guard);
685 ctx->has_used_cb = TRUE;
686 }
688 switch(nread) {
689 case 0:
690 if((ctx->total_len >= 0) && (ctx->read_len < ctx->total_len)) {
691 failf(data, "client read function EOF fail, "
692 "only %" FMT_OFF_T "/%" FMT_OFF_T " of needed bytes read",
693 ctx->read_len, ctx->total_len);
694 result = CURLE_READ_ERROR;
695 break;
696 }
697 *pnread = 0;
698 *peos = TRUE;
699 ctx->seen_eos = TRUE;
700 break;
702 case CURL_READFUNC_ABORT:
703 failf(data, "operation aborted by callback");
704 *pnread = 0;
705 *peos = FALSE;
706 ctx->errored = TRUE;
707 ctx->error_result = CURLE_ABORTED_BY_CALLBACK;
708 result = CURLE_ABORTED_BY_CALLBACK;
709 break;
711 case CURL_READFUNC_PAUSE:
712 if(data->conn->scheme->flags & PROTOPT_NONETWORK) {
713 /* protocols that work without network cannot be paused. This is
714 actually only file:// now, and it cannot pause since the transfer
715 is not done using the "normal" procedure. */
716 failf(data, "Read callback asked for PAUSE when not supported");
717 result = CURLE_READ_ERROR;
718 break;
719 }
720 /* CURL_READFUNC_PAUSE pauses read callbacks that feed socket writes */
721 CURL_TRC_READ(data, "cr_in_read, callback returned CURL_READFUNC_PAUSE");
722 ctx->is_paused = TRUE;
723 *pnread = 0;
724 *peos = FALSE;
725 result = Curl_xfer_pause_send(data, TRUE);
726 break; /* nothing was read */
728 default:
729 if(nread > blen) {
730 /* the read function returned a too large value */
731 failf(data, "read function returned funny value");
732 *pnread = 0;
733 *peos = FALSE;
734 ctx->errored = TRUE;
735 ctx->error_result = CURLE_READ_ERROR;
736 result = CURLE_READ_ERROR;
737 break;
738 }
739 ctx->read_len += nread;
740 if(ctx->total_len >= 0)
741 ctx->seen_eos = (ctx->read_len >= ctx->total_len);
742 *pnread = nread;
743 *peos = (bool)ctx->seen_eos;
744 break;
745 }
746 CURL_TRC_READ(data, "cr_in_read(len=%zu, total=%" FMT_OFF_T
747 ", read=%" FMT_OFF_T ") -> %d, nread=%zu, eos=%d",
748 blen, ctx->total_len, ctx->read_len, (int)result,
749 *pnread, *peos);
750 return result;
751}
753static bool cr_in_needs_rewind(struct Curl_easy *data,
754 struct Curl_creader *reader)
755{
756 struct cr_in_ctx *ctx = reader->ctx;
757 (void)data;
758 return (bool)ctx->has_used_cb;
759}
761static curl_off_t cr_in_total_length(struct Curl_easy *data,
762 struct Curl_creader *reader)
763{
764 struct cr_in_ctx *ctx = reader->ctx;
765 (void)data;
766 return ctx->total_len;
767}
769static CURLcode cr_in_resume_from(struct Curl_easy *data,
770 struct Curl_creader *reader,
771 curl_off_t offset)
772{
773 struct cr_in_ctx *ctx = reader->ctx;
774 int seekerr = CURL_SEEKFUNC_CANTSEEK;
776 DEBUGASSERT(data->conn);
777 /* already started reading? */
778 if(ctx->read_len)
779 return CURLE_READ_ERROR;
781 if(data->set.seek_func) {
782 struct Curl_mapi_guard guard;
783 CURL_CBAPI_START(&guard, data, easy_seek_func);
784 seekerr = data->set.seek_func(data->set.seek_client, offset, SEEK_SET);
785 CURL_CBAPI_END(&guard);
786 }
788 if(seekerr != CURL_SEEKFUNC_OK) {
789 curl_off_t passed = 0;
791 if(seekerr != CURL_SEEKFUNC_CANTSEEK) {
792 failf(data, "Could not seek stream");
793 return CURLE_READ_ERROR;
794 }
795 /* when seekerr == CURL_SEEKFUNC_CANTSEEK (cannot seek to offset) */
796 do {
797 struct Curl_mapi_guard guard;
798 char scratch[4 * 1024];
799 size_t readthisamountnow =
800 (offset - passed > (curl_off_t)sizeof(scratch)) ?
801 sizeof(scratch) :
802 curlx_sotouz(offset - passed);
803 size_t actuallyread;
805 CURL_CBAPI_START(&guard, data, easy_cr_in_resume_from);
806 actuallyread = ctx->read_cb(scratch, 1, readthisamountnow,
807 ctx->cb_user_data);
808 CURL_CBAPI_END(&guard);
810 passed += actuallyread;
811 if((actuallyread == 0) || (actuallyread > readthisamountnow)) {
812 /* this checks for greater-than only to make sure that the
813 CURL_READFUNC_ABORT return code still aborts */
814 failf(data, "Could only read %" FMT_OFF_T " bytes from the input",
815 passed);
816 return CURLE_READ_ERROR;
817 }
818 } while(passed < offset);
819 }
821 /* now, decrease the size of the read */
822 if(ctx->total_len > 0) {
823 ctx->total_len -= offset;
825 if(ctx->total_len <= 0) {
826 failf(data, "File already completely uploaded");
827 return CURLE_PARTIAL_FILE;
828 }
829 }
830 /* we have passed, proceed as normal */
831 return CURLE_OK;
832}
834static CURLcode cr_in_rewind(struct Curl_easy *data,
835 struct Curl_creader *reader)
836{
837 struct cr_in_ctx *ctx = reader->ctx;
839 /* If we never invoked the callback, there is noting to rewind */
840 if(!ctx->has_used_cb)
841 return CURLE_OK;
843 if(data->set.seek_func) {
844 struct Curl_mapi_guard guard;
845 int err;
847 CURL_CBAPI_START(&guard, data, easy_seek_func);
848 err = data->set.seek_func(data->set.seek_client, 0, SEEK_SET);
849 CURL_CBAPI_END(&guard);
850 CURL_TRC_READ(data, "cr_in, rewind via set.seek_func -> %d", err);
851 if(err) {
852 failf(data, "seek callback returned error %d", err);
853 return CURLE_SEND_FAIL_REWIND;
854 }
855 }
856 else if(data->set.ioctl_func) {
857 struct Curl_mapi_guard guard;
858 curlioerr err;
860 CURL_CBAPI_START(&guard, data, easy_ioctl_func);
861 err = data->set.ioctl_func(data, CURLIOCMD_RESTARTREAD,
862 data->set.ioctl_client);
863 CURL_CBAPI_END(&guard);
864 CURL_TRC_READ(data, "cr_in, rewind via set.ioctl_func -> %d", (int)err);
865 if(err) {
866 failf(data, "ioctl callback returned error %d", (int)err);
867 return CURLE_SEND_FAIL_REWIND;
868 }
869 }
870 else {
871 /* If no CURLOPT_READFUNCTION is used, we know that we operate on a
872 given FILE * stream and we can actually attempt to rewind that
873 ourselves with fseek() */
874#if defined(__clang__) && __clang_major__ >= 16
875#pragma clang diagnostic push
876#pragma clang diagnostic ignored "-Wcast-function-type-strict"
877#endif
878 if(data->state.fread_func == (curl_read_callback)fread) {
879#if defined(__clang__) && __clang_major__ >= 16
880#pragma clang diagnostic pop
881#endif
882 int err = fseek(data->state.in, 0, SEEK_SET);
883 CURL_TRC_READ(data, "cr_in, rewind via fseek -> %d(%d)",
884 (int)err, (int)errno);
885 if(err != -1)
886 /* successful rewind */
887 return CURLE_OK;
888 }
890 /* no callback set or failure above, makes us fail at once */
891 failf(data, "necessary data rewind was not possible");
892 return CURLE_SEND_FAIL_REWIND;
893 }
894 return CURLE_OK;
895}
897static CURLcode cr_in_cntrl(struct Curl_easy *data,
898 struct Curl_creader *reader,
899 Curl_creader_cntrl opcode)
900{
901 struct cr_in_ctx *ctx = reader->ctx;
903 switch(opcode) {
904 case CURL_CRCNTRL_REWIND:
905 return cr_in_rewind(data, reader);
906 case CURL_CRCNTRL_UNPAUSE:
907 ctx->is_paused = FALSE;
908 break;
909 case CURL_CRCNTRL_CLEAR_EOS:
910 ctx->seen_eos = FALSE;
911 break;
912 default:
913 break;
914 }
915 return CURLE_OK;
916}
918static bool cr_in_is_paused(struct Curl_easy *data,
919 struct Curl_creader *reader)
920{
921 struct cr_in_ctx *ctx = reader->ctx;
922 (void)data;
923 return (bool)ctx->is_paused;
924}
926static const struct Curl_crtype cr_in = {
927 "cr-in",
928 cr_in_init,
929 cr_in_read,
930 Curl_creader_def_close,
931 cr_in_needs_rewind,
932 cr_in_total_length,
933 cr_in_resume_from,
934 cr_in_cntrl,
935 cr_in_is_paused,
936 Curl_creader_def_done,
937 sizeof(struct cr_in_ctx)
938};
940CURLcode Curl_creader_create(struct Curl_creader **preader,
941 struct Curl_easy *data,
942 const struct Curl_crtype *crt,
943 Curl_creader_phase phase)
944{
945 struct Curl_creader *reader = NULL;
946 CURLcode result = CURLE_OUT_OF_MEMORY;
947 void *p;
949 DEBUGASSERT(crt->creader_size >= sizeof(struct Curl_creader));
950 p = curlx_calloc(1, crt->creader_size);
951 if(!p)
952 goto out;
954 reader = (struct Curl_creader *)p;
955 reader->crt = crt;
956 reader->ctx = p;
957 reader->phase = phase;
958 result = crt->do_init(data, reader);
960out:
961 *preader = result ? NULL : reader;
962 if(result)
963 curlx_free(reader);
964 return result;
965}
967void Curl_creader_free(struct Curl_easy *data, struct Curl_creader *reader)
968{
969 if(reader) {
970 reader->crt->do_close(data, reader);
971 curlx_free(reader);
972 }
973}
975struct cr_lc_ctx {
976 struct Curl_creader super;
977 struct bufq buf;
978 BIT(read_eos); /* we read an EOS from the next reader */
979 BIT(eos); /* we have returned an EOS */
980 BIT(prev_cr); /* the last byte was a CR */
981};
983static CURLcode cr_lc_init(struct Curl_easy *data, struct Curl_creader *reader)
984{
985 struct cr_lc_ctx *ctx = reader->ctx;
986 (void)data;
987 Curl_bufq_init2(&ctx->buf, (16 * 1024), 1, BUFQ_OPT_SOFT_LIMIT);
988 return CURLE_OK;
989}
991static void cr_lc_close(struct Curl_easy *data, struct Curl_creader *reader)
992{
993 struct cr_lc_ctx *ctx = reader->ctx;
994 (void)data;
995 Curl_bufq_free(&ctx->buf);
996}
998/* client reader doing line end conversions. */
999static CURLcode cr_lc_read(struct Curl_easy *data,
1000 struct Curl_creader *reader,
1001 char *buf, size_t blen,
1002 size_t *pnread, bool *peos)
1003{
1004 struct cr_lc_ctx *ctx = reader->ctx;
1005 CURLcode result;
1006 size_t nread, i, start, n;
1007 bool eos;
1009 if(ctx->eos) {
1010 *pnread = 0;
1011 *peos = TRUE;
1012 return CURLE_OK;
1013 }
1015 if(Curl_bufq_is_empty(&ctx->buf)) {
1016 if(ctx->read_eos) {
1017 ctx->eos = TRUE;
1018 *pnread = 0;
1019 *peos = TRUE;
1020 return CURLE_OK;
1021 }
1022 /* Still getting data form the next reader, ctx->buf is empty */
1023 result = Curl_creader_read(data, reader->next, buf, blen, &nread, &eos);
1024 if(result)
1025 return result;
1026 ctx->read_eos = eos;
1028 if(!nread || !memchr(buf, '\n', nread)) {
1029 /* nothing to convert, return this right away */
1030 if(nread)
1031 ctx->prev_cr = (buf[nread - 1] == '\r');
1032 if(ctx->read_eos)
1033 ctx->eos = TRUE;
1034 *pnread = nread;
1035 *peos = (bool)ctx->eos;
1036 goto out;
1037 }
1039 /* at least one \n might need conversion to '\r\n', place into ctx->buf */
1040 for(i = start = 0; i < nread; ++i) {
1041 /* if this byte is not an LF character, or if the preceding character is
1042 a CR (meaning this already is a CRLF pair), go to next */
1043 if((buf[i] != '\n') || ctx->prev_cr) {
1044 ctx->prev_cr = (buf[i] == '\r');
1045 continue;
1046 }
1047 ctx->prev_cr = FALSE;
1048 /* on a soft limit bufq, we do not need to check length */
1049 result = Curl_bufq_cwrite(&ctx->buf, buf + start, i - start, &n);
1050 if(!result)
1051 result = Curl_bufq_cwrite(&ctx->buf, STRCONST("\r\n"), &n);
1052 if(result)
1053 return result;
1054 start = i + 1;
1055 }
1057 if(start < i) { /* leftover */
1058 result = Curl_bufq_cwrite(&ctx->buf, buf + start, i - start, &n);
1059 if(result)
1060 return result;
1061 }
1062 }
1064 DEBUGASSERT(!Curl_bufq_is_empty(&ctx->buf));
1065 *peos = FALSE;
1066 result = Curl_bufq_cread(&ctx->buf, buf, blen, pnread);
1067 if(!result && ctx->read_eos && Curl_bufq_is_empty(&ctx->buf)) {
1068 /* no more data, read all, done. */
1069 ctx->eos = TRUE;
1070 *peos = TRUE;
1071 }
1073out:
1074 CURL_TRC_READ(data, "cr_lc_read(len=%zu) -> %d, nread=%zu, eos=%d",
1075 blen, (int)result, *pnread, *peos);
1076 return result;
1077}
1079static curl_off_t cr_lc_total_length(struct Curl_easy *data,
1080 struct Curl_creader *reader)
1081{
1082 /* this reader changes length depending on input */
1083 (void)data;
1084 (void)reader;
1085 return -1;
1086}
1088static const struct Curl_crtype cr_lc = {
1089 "cr-lineconv",
1090 cr_lc_init,
1091 cr_lc_read,
1092 cr_lc_close,
1093 Curl_creader_def_needs_rewind,
1094 cr_lc_total_length,
1095 Curl_creader_def_resume_from,
1096 Curl_creader_def_cntrl,
1097 Curl_creader_def_is_paused,
1098 Curl_creader_def_done,
1099 sizeof(struct cr_lc_ctx)
1100};
1102static CURLcode cr_lc_add(struct Curl_easy *data)
1103{
1104 struct Curl_creader *reader = NULL;
1105 CURLcode result;
1107 result = Curl_creader_create(&reader, data, &cr_lc, CURL_CR_CONTENT_ENCODE);
1108 if(!result)
1109 result = Curl_creader_add(data, reader);
1111 if(result && reader)
1112 Curl_creader_free(data, reader);
1113 return result;
1114}
1116static CURLcode do_init_reader_stack(struct Curl_easy *data,
1117 struct Curl_creader *r)
1118{
1119 CURLcode result = CURLE_OK;
1120 curl_off_t clen;
1122 DEBUGASSERT(r);
1123 DEBUGASSERT(r->crt);
1124 DEBUGASSERT(r->phase == CURL_CR_CLIENT);
1125 DEBUGASSERT(!data->req.reader.stack);
1127 data->req.reader.stack = r;
1128 clen = r->crt->total_length(data, r);
1129 /* if we do not have 0 length init, and CRLF conversion is wanted,
1130 * add the reader for it */
1131 if(clen &&
1132#ifdef CURL_PREFER_LF_LINEENDS
1133 (data->set.crlf || data->state.prefer_ascii)
1134#else
1135 data->set.crlf
1136#endif
1137 ) {
1138 result = cr_lc_add(data);
1139 if(result) {
1140 /* Adding the line-conversion reader failed. Undo the publication of
1141 * `r` so no freed reader remains reachable from
1142 * `data->req.reader.stack`, and free the readers already installed. */
1143 cl_reset_reader(data);
1144 return result;
1145 }
1146 }
1148 return result;
1149}
1151CURLcode Curl_creader_set_fread(struct Curl_easy *data, curl_off_t len)
1152{
1153 CURLcode result;
1154 struct Curl_creader *r;
1155 struct cr_in_ctx *ctx;
1157 result = Curl_creader_create(&r, data, &cr_in, CURL_CR_CLIENT);
1158 if(result || !r)
1159 goto out;
1160 ctx = r->ctx;
1161 ctx->total_len = len;
1163 cl_reset_reader(data);
1164 result = do_init_reader_stack(data, r);
1165out:
1166 CURL_TRC_READ(data, "add fread reader, len=%" FMT_OFF_T " -> %d",
1167 len, (int)result);
1168 return result;
1169}
1171CURLcode Curl_creader_add(struct Curl_easy *data,
1172 struct Curl_creader *reader)
1173{
1174 CURLcode result;
1175 struct Curl_creader **anchor = &data->req.reader.stack;
1177 if(!*anchor) {
1178 result = Curl_creader_set_fread(data, data->state.infilesize);
1179 if(result)
1180 return result;
1181 }
1183 /* Insert the writer as first in its phase.
1184 * Skip existing readers of lower phases. */
1185 while(*anchor && (*anchor)->phase < reader->phase)
1186 anchor = &(*anchor)->next;
1187 reader->next = *anchor;
1188 *anchor = reader;
1189 return CURLE_OK;
1190}
1192CURLcode Curl_creader_set(struct Curl_easy *data, struct Curl_creader *r)
1193{
1194 DEBUGASSERT(r);
1195 DEBUGASSERT(r->crt);
1196 DEBUGASSERT(r->phase == CURL_CR_CLIENT);
1198 cl_reset_reader(data);
1199 return do_init_reader_stack(data, r);
1200}
1202CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen,
1203 size_t *nread, bool *eos)
1204{
1205 CURLcode result;
1207 DEBUGASSERT(buf);
1208 DEBUGASSERT(blen);
1209 DEBUGASSERT(nread);
1210 DEBUGASSERT(eos);
1211 *nread = 0;
1213 if(!data->req.reader.stack) {
1214 result = Curl_creader_set_fread(data, data->state.infilesize);
1215 if(result)
1216 return result;
1217 DEBUGASSERT(data->req.reader.stack);
1218 }
1219 if(!data->req.reader_started) {
1220 Curl_rlimit_start(&data->progress.ul.rlimit, Curl_pgrs_now(data), -1);
1221 data->req.reader_started = TRUE;
1222 }
1224 if(Curl_rlimit_active(&data->progress.ul.rlimit)) {
1225 curl_off_t ul_avail = Curl_rlimit_avail(&data->progress.ul.rlimit, NULL);
1226 if(ul_avail <= 0) {
1227 result = CURLE_OK;
1228 *eos = FALSE;
1229 goto out;
1230 }
1231 if(ul_avail < (curl_off_t)blen)
1232 blen = (size_t)ul_avail;
1233 }
1234 result = Curl_creader_read(data, data->req.reader.stack, buf, blen,
1235 nread, eos);
1237out:
1238 CURL_TRC_READ(data, "client_read(len=%zu) -> %d, nread=%zu, eos=%d",
1239 blen, (int)result, *nread, *eos);
1240 return result;
1241}
1243bool Curl_creader_needs_rewind(struct Curl_easy *data)
1244{
1245 struct Curl_creader *reader = data->req.reader.stack;
1246 while(reader) {
1247 if(reader->crt->needs_rewind(data, reader)) {
1248 CURL_TRC_READ(data, "client reader needs rewind before next request");
1249 return TRUE;
1250 }
1251 reader = reader->next;
1252 }
1253 return FALSE;
1254}
1256static CURLcode cr_null_read(struct Curl_easy *data,
1257 struct Curl_creader *reader,
1258 char *buf, size_t blen,
1259 size_t *pnread, bool *peos)
1260{
1261 (void)data;
1262 (void)reader;
1263 (void)buf;
1264 (void)blen;
1265 *pnread = 0;
1266 *peos = TRUE;
1267 return CURLE_OK;
1268}
1270static curl_off_t cr_null_total_length(struct Curl_easy *data,
1271 struct Curl_creader *reader)
1272{
1273 /* this reader changes length depending on input */
1274 (void)data;
1275 (void)reader;
1276 return 0;
1277}
1279static const struct Curl_crtype cr_null = {
1280 "cr-null",
1281 Curl_creader_def_init,
1282 cr_null_read,
1283 Curl_creader_def_close,
1284 Curl_creader_def_needs_rewind,
1285 cr_null_total_length,
1286 Curl_creader_def_resume_from,
1287 Curl_creader_def_cntrl,
1288 Curl_creader_def_is_paused,
1289 Curl_creader_def_done,
1290 sizeof(struct Curl_creader)
1291};
1293CURLcode Curl_creader_set_null(struct Curl_easy *data)
1294{
1295 struct Curl_creader *r;
1296 CURLcode result;
1298 result = Curl_creader_create(&r, data, &cr_null, CURL_CR_CLIENT);
1299 if(result)
1300 return result;
1302 cl_reset_reader(data);
1303 return do_init_reader_stack(data, r);
1304}
1306struct cr_buf_ctx {
1307 struct Curl_creader super;
1308 const char *buf;
1309 size_t blen;
1310 size_t index;
1311};
1313static CURLcode cr_buf_read(struct Curl_easy *data,
1314 struct Curl_creader *reader,
1315 char *buf, size_t blen,
1316 size_t *pnread, bool *peos)
1317{
1318 struct cr_buf_ctx *ctx = reader->ctx;
1319 size_t nread = ctx->blen - ctx->index;
1321 if(!nread || !ctx->buf) {
1322 *pnread = 0;
1323 *peos = TRUE;
1324 }
1325 else {
1326 if(nread > blen)
1327 nread = blen;
1328 memcpy(buf, ctx->buf + ctx->index, nread);
1329 *pnread = nread;
1330 ctx->index += nread;
1331 *peos = (ctx->index == ctx->blen);
1332 }
1333 CURL_TRC_READ(data, "cr_buf_read(len=%zu) -> 0, nread=%zu, eos=%d",
1334 blen, *pnread, *peos);
1335 return CURLE_OK;
1336}
1338static bool cr_buf_needs_rewind(struct Curl_easy *data,
1339 struct Curl_creader *reader)
1340{
1341 struct cr_buf_ctx *ctx = reader->ctx;
1342 (void)data;
1343 return ctx->index > 0;
1344}
1346static CURLcode cr_buf_cntrl(struct Curl_easy *data,
1347 struct Curl_creader *reader,
1348 Curl_creader_cntrl opcode)
1349{
1350 struct cr_buf_ctx *ctx = reader->ctx;
1351 (void)data;
1352 switch(opcode) {
1353 case CURL_CRCNTRL_REWIND:
1354 ctx->index = 0;
1355 break;
1356 default:
1357 break;
1358 }
1359 return CURLE_OK;
1360}
1362static curl_off_t cr_buf_total_length(struct Curl_easy *data,
1363 struct Curl_creader *reader)
1364{
1365 struct cr_buf_ctx *ctx = reader->ctx;
1366 (void)data;
1367 return (curl_off_t)ctx->blen;
1368}
1370static CURLcode cr_buf_resume_from(struct Curl_easy *data,
1371 struct Curl_creader *reader,
1372 curl_off_t offset)
1373{
1374 struct cr_buf_ctx *ctx = reader->ctx;
1375 size_t boffset;
1377 (void)data;
1378 DEBUGASSERT(data->conn);
1379 /* already started reading? */
1380 if(ctx->index)
1381 return CURLE_READ_ERROR;
1382 boffset = curlx_sotouz_range(offset, 0, SIZE_MAX);
1383 if(!boffset)
1384 return CURLE_OK;
1385 if(boffset > ctx->blen)
1386 return CURLE_READ_ERROR;
1388 ctx->buf += boffset;
1389 ctx->blen -= boffset;
1390 return CURLE_OK;
1391}
1393static const struct Curl_crtype cr_buf = {
1394 "cr-buf",
1395 Curl_creader_def_init,
1396 cr_buf_read,
1397 Curl_creader_def_close,
1398 cr_buf_needs_rewind,
1399 cr_buf_total_length,
1400 cr_buf_resume_from,
1401 cr_buf_cntrl,
1402 Curl_creader_def_is_paused,
1403 Curl_creader_def_done,
1404 sizeof(struct cr_buf_ctx)
1405};
1407CURLcode Curl_creader_set_buf(struct Curl_easy *data,
1408 const char *buf, size_t blen)
1409{
1410 CURLcode result;
1411 struct Curl_creader *r;
1412 struct cr_buf_ctx *ctx;
1414 result = Curl_creader_create(&r, data, &cr_buf, CURL_CR_CLIENT);
1415 if(result)
1416 goto out;
1417 ctx = r->ctx;
1418 ctx->buf = buf;
1419 ctx->blen = blen;
1420 ctx->index = 0;
1422 cl_reset_reader(data);
1423 result = do_init_reader_stack(data, r);
1424out:
1425 CURL_TRC_READ(data, "add buf reader, len=%zu -> %d", blen, (int)result);
1426 return result;
1427}
1429curl_off_t Curl_creader_total_length(struct Curl_easy *data)
1430{
1431 struct Curl_creader *r = data->req.reader.stack;
1432 return r ? r->crt->total_length(data, r) : -1;
1433}
1435curl_off_t Curl_creader_client_length(struct Curl_easy *data)
1436{
1437 struct Curl_creader *r = data->req.reader.stack;
1438 while(r && r->phase != CURL_CR_CLIENT)
1439 r = r->next;
1440 return r ? r->crt->total_length(data, r) : -1;
1441}
1443CURLcode Curl_creader_unpause(struct Curl_easy *data)
1444{
1445 struct Curl_creader *reader = data->req.reader.stack;
1446 CURLcode result = CURLE_OK;
1448 while(reader) {
1449 result = reader->crt->cntrl(data, reader, CURL_CRCNTRL_UNPAUSE);
1450 CURL_TRC_READ(data, "unpausing %s -> %d", reader->crt->name, (int)result);
1451 if(result)
1452 break;
1453 reader = reader->next;
1454 }
1455 return result;
1456}
1458bool Curl_creader_is_paused(struct Curl_easy *data)
1459{
1460 struct Curl_creader *reader = data->req.reader.stack;
1462 while(reader) {
1463 if(reader->crt->is_paused(data, reader))
1464 return TRUE;
1465 reader = reader->next;
1466 }
1467 return FALSE;
1468}
1470void Curl_creader_done(struct Curl_easy *data, int premature)
1471{
1472 struct Curl_creader *reader = data->req.reader.stack;
1473 while(reader) {
1474 reader->crt->done(data, reader, premature);
1475 reader = reader->next;
1476 }
1477}
1479struct Curl_creader *Curl_creader_get_by_type(struct Curl_easy *data,
1480 const struct Curl_crtype *crt)
1481{
1482 struct Curl_creader *r;
1483 for(r = data->req.reader.stack; r; r = r->next) {
1484 if(r->crt == crt)
1485 return r;
1486 }
1487 return NULL;
1488}
Diagnostics4 git calls · 199 ms
CallStatusSizeTime0199 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 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 · hit5 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=191 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=5 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch20010 KiB191 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=10340 git.response.cache=MISS git.response.duration_ms=191 git.fetch.wants=41b2ca0eccebc13e0b92db557f9b5ba3b84c7738 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=10340 git.pkt.payload.max=10319 git.sideband.band1.bytes=10318 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
- a5e261576912224d
- Request
- b639cd36…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format