Artifactspublic-v0

curl

master
ply4 git calls26 ms292 KiB3 cachedprotocol v2
418 lines16 KiBRaw
1#ifndef HEADER_CURL_SENDF_H
2#define HEADER_CURL_SENDF_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11 *
12 * This software is licensed as described in the file COPYING, which
13 * you should have received as part of this distribution. The terms
14 * are also available at https://curl.se/docs/copyright.html.
15 *
16 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17 * copies of the Software, and permit persons to whom the Software is
18 * furnished to do so, under the terms of the COPYING file.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 * SPDX-License-Identifier: curl
24 *
25 ***************************************************************************/
26#include "curl_setup.h"
27#include "cw-out.h"
29/**
30 * Type of data that is being written to the client (application)
31 * - data written can be either BODY or META data
32 * - META data is either INFO or HEADER
33 * - INFO is meta information, e.g. not BODY, that cannot be interpreted
34 * as headers of a response. Example FTP/IMAP pingpong answers.
35 * - HEADER can have additional bits set (more than one)
36 * - STATUS special "header", e.g. response status line in HTTP
37 * - CONNECT header was received during proxying the connection
38 * - 1XX header is part of an intermediate response, e.g. HTTP 1xx code
39 * - TRAILER header is trailing response data, e.g. HTTP trailers
40 * BODY, INFO and HEADER should not be mixed, as this would lead to
41 * confusion on how to interpret/format/convert the data.
42 */
43#define CLIENTWRITE_BODY (1 << 0) /* non-meta information, BODY */
44#define CLIENTWRITE_INFO (1 << 1) /* meta information, not a HEADER */
45#define CLIENTWRITE_HEADER (1 << 2) /* meta information, HEADER */
46#define CLIENTWRITE_STATUS (1 << 3) /* a special status HEADER */
47#define CLIENTWRITE_CONNECT (1 << 4) /* a CONNECT related HEADER */
48#define CLIENTWRITE_1XX (1 << 5) /* a 1xx response related HEADER */
49#define CLIENTWRITE_TRAILER (1 << 6) /* a trailer HEADER */
50#define CLIENTWRITE_EOS (1 << 7) /* End Of transfer download Stream */
51#define CLIENTWRITE_0LEN (1 << 8) /* write even 0-length buffers */
53/* Forward declarations */
54struct Curl_creader;
55struct Curl_cwriter;
56struct Curl_easy;
58/**
59 * Write `len` bytes at `buf` to the client. `type` indicates what
60 * kind of data is being written.
61 */
62CURLcode Curl_client_write(struct Curl_easy *data, int type, const char *buf,
63 size_t len) WARN_UNUSED_RESULT;
65/* Flush buffered data. Set eos when no more input will be written. */
66CURLcode Curl_client_flush(struct Curl_easy *data, bool eos);
68/**
69 * Free all resources related to client writing.
70 */
71void Curl_client_cleanup(struct Curl_easy *data);
73/**
74 * Reset readers and writer chains, keep rewind information
75 * when necessary.
76 */
77void Curl_client_reset(struct Curl_easy *data);
79/**
80 * A new request is starting, perform any ops like rewinding
81 * previous readers when needed.
82 */
83CURLcode Curl_client_start(struct Curl_easy *data);
85/**
86 * Client Writers - a chain passing transfer BODY data to the client.
87 * Main application: HTTP and related protocols
88 * Other uses: monitoring of download progress
89 *
90 * Writers in the chain are order by their `phase`. First come all
91 * writers in CURL_CW_RAW, followed by any in CURL_CW_TRANSFER_DECODE,
92 * followed by any in CURL_CW_PROTOCOL, etc.
93 *
94 * When adding a writer, it is inserted as first in its phase. This means
95 * the order of adding writers of the same phase matters, but writers for
96 * different phases may be added in any order.
97 *
98 * Writers which do modify the BODY data written are expected to be of
99 * phases TRANSFER_DECODE or CONTENT_DECODE. The other phases are intended
100 * for monitoring writers. Which do *not* modify the data but gather
101 * statistics or update progress reporting.
102 */
104/* Phase a writer operates at. */
105typedef enum {
106 CURL_CW_RAW, /* raw data written, before any decoding */
107 CURL_CW_TRANSFER_DECODE, /* remove transfer-encodings */
108 CURL_CW_PROTOCOL, /* after transfer, but before content decoding */
109 CURL_CW_BEFORE_DECODE, /* after protocol, but before content decoding */
110 CURL_CW_CONTENT_DECODE, /* remove content-encodings */
111 CURL_CW_CLIENT /* data written to client */
112} Curl_cwriter_phase;
114/* writer may blow up size of write data, e.g. zip bombs */
115#define CURL_CW_FLAG_BLOWUP (1U << 0)
117/* Client Writer Type, provides the implementation */
118struct Curl_cwtype {
119 const char *name; /* writer name. */
120 const char *alias; /* writer name alias, maybe NULL. */
121 uint8_t flags; /* flags for writer behaviour */
122 CURLcode (*do_init)(struct Curl_easy *data,
123 struct Curl_cwriter *writer);
124 CURLcode (*do_write)(struct Curl_easy *data,
125 struct Curl_cwriter *writer, int type,
126 const char *buf, size_t nbytes);
127 CURLcode (*do_flush)(struct Curl_easy *data,
128 struct Curl_cwriter *writer, bool eos);
129 void (*do_close)(struct Curl_easy *data,
130 struct Curl_cwriter *writer);
131 size_t cwriter_size; /* sizeof() allocated struct Curl_cwriter */
132};
134/* Client writer instance, allocated on creation.
135 * `void *ctx` is the pointer from the allocation of
136 * the `struct Curl_cwriter` itself. This is suitable for "downcasting"
137 * by the writers implementation. See https://github.com/curl/curl/pull/13054
138 * for the alignment problems that arise otherwise.
139 */
140struct Curl_cwriter {
141 const struct Curl_cwtype *cwt; /* type implementation */
142 struct Curl_cwriter *next; /* Downstream writer. */
143 void *ctx; /* allocated instance pointer */
144 Curl_cwriter_phase phase; /* phase at which it operates */
145};
147/**
148 * Create a new cwriter instance with given type and phase. Is not
149 * inserted into the writer chain by this call.
150 * Invokes `writer->do_init()`.
151 */
152CURLcode Curl_cwriter_create(struct Curl_cwriter **pwriter,
153 struct Curl_easy *data,
154 const struct Curl_cwtype *cwt,
155 Curl_cwriter_phase phase);
157/**
158 * Free a cwriter instance.
159 * Invokes `writer->do_close()`.
160 */
161void Curl_cwriter_free(struct Curl_easy *data,
162 struct Curl_cwriter *writer);
164/**
165 * Count the number of writers installed of the given phase.
166 */
167size_t Curl_cwriter_count(struct Curl_easy *data, Curl_cwriter_phase phase);
169/**
170 * Adds a writer to the transfer's writer chain.
171 * The writers `phase` determines where in the chain it is inserted.
172 */
173CURLcode Curl_cwriter_add(struct Curl_easy *data,
174 struct Curl_cwriter *writer);
176/**
177 * Look up an installed client writer on `data` by its type.
178 * @return first writer with that type or NULL
179 */
180struct Curl_cwriter *Curl_cwriter_get_by_type(struct Curl_easy *data,
181 const struct Curl_cwtype *cwt);
183struct Curl_cwriter *Curl_cwriter_get_by_name(struct Curl_easy *data,
184 const char *name);
186/* Convenience method for calling `writer->do_write()` that
187 * checks for NULL writer. */
188#define Curl_cwriter_write(d, w, t, b, n) \
189 ((w) ? (w)->cwt->do_write((d), (w), (t), (b), (n)) : CURLE_WRITE_ERROR)
191#define Curl_cwriter_flush(d, w, eos) \
192 ((w) ? (w)->cwt->do_flush((d), (w), (eos)) : CURLE_WRITE_ERROR)
194/* TRUE if client writer is paused. */
195#define Curl_cwriter_is_paused(d) ((bool)(d)->req.writer.paused)
197/**
198 * Unpause client writer and flush any buffered date to the client.
199 */
200CURLcode Curl_cwriter_unpause(struct Curl_easy *data);
202/**
203 * Default implementations for do_init, do_write, do_close that
204 * do nothing and pass the data through.
205 */
206CURLcode Curl_cwriter_def_init(struct Curl_easy *data,
207 struct Curl_cwriter *writer);
208CURLcode Curl_cwriter_def_write(struct Curl_easy *data,
209 struct Curl_cwriter *writer, int type,
210 const char *buf, size_t nbytes);
211CURLcode Curl_cwriter_def_flush(struct Curl_easy *data,
212 struct Curl_cwriter *writer, bool eos);
213void Curl_cwriter_def_close(struct Curl_easy *data,
214 struct Curl_cwriter *writer);
216typedef enum {
217 CURL_CRCNTRL_REWIND,
218 CURL_CRCNTRL_UNPAUSE,
219 CURL_CRCNTRL_CLEAR_EOS
220} Curl_creader_cntrl;
222/* Client Reader Type, provides the implementation */
223struct Curl_crtype {
224 const char *name; /* writer name. */
225 CURLcode (*do_init)(struct Curl_easy *data, struct Curl_creader *reader);
226 CURLcode (*do_read)(struct Curl_easy *data, struct Curl_creader *reader,
227 char *buf, size_t blen, size_t *nread, bool *eos);
228 void (*do_close)(struct Curl_easy *data, struct Curl_creader *reader);
229 bool (*needs_rewind)(struct Curl_easy *data, struct Curl_creader *reader);
230 curl_off_t (*total_length)(struct Curl_easy *data,
231 struct Curl_creader *reader);
232 CURLcode (*resume_from)(struct Curl_easy *data,
233 struct Curl_creader *reader, curl_off_t offset);
234 CURLcode (*cntrl)(struct Curl_easy *data, struct Curl_creader *reader,
235 Curl_creader_cntrl opcode);
236 bool (*is_paused)(struct Curl_easy *data, struct Curl_creader *reader);
237 void (*done)(struct Curl_easy *data,
238 struct Curl_creader *reader, int premature);
239 size_t creader_size; /* sizeof() allocated struct Curl_creader */
240};
242/* Phase a reader operates at. */
243typedef enum {
244 CURL_CR_NET, /* data send to the network (connection filters) */
245 CURL_CR_TRANSFER_ENCODE, /* add transfer-encodings */
246 CURL_CR_PROTOCOL, /* before transfer, but after content decoding */
247 CURL_CR_CONTENT_ENCODE, /* add content-encodings */
248 CURL_CR_CLIENT /* data read from client */
249} Curl_creader_phase;
251/* Client reader instance, allocated on creation.
252 * `void *ctx` is the pointer from the allocation of
253 * the `struct Curl_cwriter` itself. This is suitable for "downcasting"
254 * by the writers implementation. See https://github.com/curl/curl/pull/13054
255 * for the alignment problems that arise otherwise.
256 */
257struct Curl_creader {
258 const struct Curl_crtype *crt; /* type implementation */
259 struct Curl_creader *next; /* Downstream reader. */
260 void *ctx;
261 Curl_creader_phase phase; /* phase at which it operates */
262};
264/**
265 * Default implementations for do_init, do_write, do_close that
266 * do nothing and pass the data through.
267 */
268CURLcode Curl_creader_def_init(struct Curl_easy *data,
269 struct Curl_creader *reader);
270void Curl_creader_def_close(struct Curl_easy *data,
271 struct Curl_creader *reader);
272CURLcode Curl_creader_def_read(struct Curl_easy *data,
273 struct Curl_creader *reader,
274 char *buf, size_t blen,
275 size_t *nread, bool *eos);
276bool Curl_creader_def_needs_rewind(struct Curl_easy *data,
277 struct Curl_creader *reader);
278curl_off_t Curl_creader_def_total_length(struct Curl_easy *data,
279 struct Curl_creader *reader);
280CURLcode Curl_creader_def_resume_from(struct Curl_easy *data,
281 struct Curl_creader *reader,
282 curl_off_t offset);
283CURLcode Curl_creader_def_cntrl(struct Curl_easy *data,
284 struct Curl_creader *reader,
285 Curl_creader_cntrl opcode);
286bool Curl_creader_def_is_paused(struct Curl_easy *data,
287 struct Curl_creader *reader);
288void Curl_creader_def_done(struct Curl_easy *data,
289 struct Curl_creader *reader, int premature);
291/**
292 * Convenience method for calling `reader->do_read()` that
293 * checks for NULL reader.
294 */
295CURLcode Curl_creader_read(struct Curl_easy *data,
296 struct Curl_creader *reader,
297 char *buf, size_t blen, size_t *nread, bool *eos);
299/* Tell the reader and all below that any EOS state is to be cleared */
300void Curl_creader_clear_eos(struct Curl_easy *data,
301 struct Curl_creader *reader);
303/**
304 * Create a new creader instance with given type and phase. Is not
305 * inserted into the writer chain by this call.
306 * Invokes `reader->do_init()`.
307 */
308CURLcode Curl_creader_create(struct Curl_creader **preader,
309 struct Curl_easy *data,
310 const struct Curl_crtype *crt,
311 Curl_creader_phase phase);
313/**
314 * Free a creader instance.
315 * Invokes `reader->do_close()`.
316 */
317void Curl_creader_free(struct Curl_easy *data, struct Curl_creader *reader);
319/**
320 * Adds a reader to the transfer's reader chain.
321 * The readers `phase` determines where in the chain it is inserted.
322 */
323CURLcode Curl_creader_add(struct Curl_easy *data,
324 struct Curl_creader *reader);
326/**
327 * Set the given reader, which needs to be of type CURL_CR_CLIENT,
328 * as the new first reader. Discard any installed readers and init
329 * the reader chain anew.
330 * The function takes ownership of `r`.
331 */
332CURLcode Curl_creader_set(struct Curl_easy *data, struct Curl_creader *r);
334/**
335 * Read at most `blen` bytes at `buf` from the client.
336 * @param data the transfer to read client bytes for
337 * @param buf the memory location to read to
338 * @param blen the amount of memory at `buf`
339 * @param nread on return the number of bytes read into `buf`
340 * @param eos TRUE iff bytes are the end of data from client
341 * @return CURLE_OK on successful read (even 0 length) or error
342 */
343CURLcode Curl_client_read(struct Curl_easy *data, char *buf, size_t blen,
344 size_t *nread, bool *eos) WARN_UNUSED_RESULT;
346/**
347 * TRUE iff client reader needs rewing before it can be used for
348 * a retry request.
349 */
350bool Curl_creader_needs_rewind(struct Curl_easy *data);
352/**
353 * TRUE iff client reader will rewind at next start
354 */
355bool Curl_creader_will_rewind(struct Curl_easy *data);
357/**
358 * En-/disable rewind of client reader at next start.
359 */
360void Curl_creader_set_rewind(struct Curl_easy *data, bool enable);
362/**
363 * Get the total length of bytes provided by the installed readers.
364 * This is independent of the amount already delivered and is calculated
365 * by all readers in the stack. If a reader like "chunked" or
366 * "crlf conversion" is installed, the returned length will be -1.
367 * @return -1 if length is indeterminate
368 */
369curl_off_t Curl_creader_total_length(struct Curl_easy *data);
371/**
372 * Get the total length of bytes provided by the reader at phase
373 * CURL_CR_CLIENT. This may not match the amount of bytes read
374 * for a request, depending if other, encoding readers are also installed.
375 * However it allows for rough estimation of the overall length.
376 * @return -1 if length is indeterminate
377 */
378curl_off_t Curl_creader_client_length(struct Curl_easy *data);
380/**
381 * Unpause all installed readers.
382 */
383CURLcode Curl_creader_unpause(struct Curl_easy *data);
385/**
386 * Return TRUE iff any of the installed readers is paused.
387 */
388bool Curl_creader_is_paused(struct Curl_easy *data);
390/**
391 * Tell all client readers that they are done.
392 */
393void Curl_creader_done(struct Curl_easy *data, int premature);
395/**
396 * Look up an installed client reader on `data` by its type.
397 * @return first reader with that type or NULL
398 */
399struct Curl_creader *Curl_creader_get_by_type(struct Curl_easy *data,
400 const struct Curl_crtype *crt);
402/**
403 * Set the client reader to provide 0 bytes, immediate EOS.
404 */
405CURLcode Curl_creader_set_null(struct Curl_easy *data);
407/**
408 * Set the client reader the reads from fread callback.
409 */
410CURLcode Curl_creader_set_fread(struct Curl_easy *data, curl_off_t len);
412/**
413 * Set the client reader the reads from the supplied buf (NOT COPIED).
414 */
415CURLcode Curl_creader_set_buf(struct Curl_easy *data,
416 const char *buf, size_t blen);
418#endif /* HEADER_CURL_SENDF_H */
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 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 · 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 · 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
fetch2004.6 KiB · hit20 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=20
git.response.bytes=4759
git.response.cache=HIT
git.response.duration_ms=20
git.fetch.wants=6975ad1e6182a2226c86c951016d247bbdac60a4
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=4759
git.pkt.payload.max=4738
git.sideband.band1.bytes=4737
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
a5e155f8884190ce
Request
79755da1…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format