Artifactspublic-v0

curl

master
ply4 git calls112 ms290 KiB2 cachedprotocol v2
401 lines11 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#include "dynhds.h"
27#include "strcase.h"
29static struct dynhds_entry *entry_new(const char *name, size_t namelen,
30 const char *value, size_t valuelen,
31 int opts)
33 struct dynhds_entry *e;
34 char *p;
36 /* namelen + valuelen <= SIZE_MAX has already been checked by caller */
37 if((SIZE_MAX - namelen - valuelen) < (sizeof(*e) + 2))
38 return NULL;
39 e = curlx_calloc(1, sizeof(*e) + namelen + valuelen + 2);
40 if(!e)
41 return NULL;
42 e->name = p = (char *)e + sizeof(*e);
43 memcpy(p, name, namelen);
44 e->namelen = namelen;
45 e->value = p += namelen + 1; /* leave a \0 at the end of name */
46 if(valuelen) {
47 memcpy(p, value, valuelen);
48 e->valuelen = valuelen;
49 }
50 if(opts & DYNHDS_OPT_LOWERCASE)
51 Curl_strntolower(e->name, e->name, e->namelen);
52 return e;
55static void entry_free(struct dynhds_entry *e)
57 curlx_free(e);
60void Curl_dynhds_init(struct dynhds *dynhds, size_t max_entries,
61 size_t max_strs_size)
63 DEBUGASSERT(dynhds);
64 DEBUGASSERT(max_strs_size);
65 dynhds->hds = NULL;
66 dynhds->hds_len = dynhds->hds_allc = dynhds->strs_len = 0;
67 dynhds->max_entries = max_entries;
68 dynhds->max_strs_size = max_strs_size;
69 dynhds->opts = 0;
72void Curl_dynhds_free(struct dynhds *dynhds)
74 DEBUGASSERT(dynhds);
75 if(dynhds->hds && dynhds->hds_len) {
76 size_t i;
77 DEBUGASSERT(dynhds->hds);
78 for(i = 0; i < dynhds->hds_len; ++i) {
79 entry_free(dynhds->hds[i]);
80 }
81 }
82 curlx_safefree(dynhds->hds);
83 dynhds->hds_len = dynhds->hds_allc = dynhds->strs_len = 0;
86void Curl_dynhds_reset(struct dynhds *dynhds)
88 DEBUGASSERT(dynhds);
89 if(dynhds->hds_len) {
90 size_t i;
91 DEBUGASSERT(dynhds->hds);
92 for(i = 0; i < dynhds->hds_len; ++i) {
93 entry_free(dynhds->hds[i]);
94 dynhds->hds[i] = NULL;
95 }
96 }
97 dynhds->hds_len = dynhds->strs_len = 0;
100size_t Curl_dynhds_count(struct dynhds *dynhds)
102 return dynhds->hds_len;
105void Curl_dynhds_set_opts(struct dynhds *dynhds, int opts)
107 dynhds->opts = opts;
110struct dynhds_entry *Curl_dynhds_getn(struct dynhds *dynhds, size_t n)
112 DEBUGASSERT(dynhds);
113 return (n < dynhds->hds_len) ? dynhds->hds[n] : NULL;
116struct dynhds_entry *Curl_dynhds_get(struct dynhds *dynhds, const char *name,
117 size_t namelen)
119 size_t i;
120 for(i = 0; i < dynhds->hds_len; ++i) {
121 if(dynhds->hds[i]->namelen == namelen &&
122 curl_strnequal(dynhds->hds[i]->name, name, namelen)) {
123 return dynhds->hds[i];
124 }
125 }
126 return NULL;
129struct dynhds_entry *Curl_dynhds_cget(struct dynhds *dynhds, const char *name)
131 return Curl_dynhds_get(dynhds, name, strlen(name));
134CURLcode Curl_dynhds_add(struct dynhds *dynhds,
135 const char *name, size_t namelen,
136 const char *value, size_t valuelen)
138 struct dynhds_entry *entry = NULL;
139 CURLcode result = CURLE_OUT_OF_MEMORY;
141 /* Accept NULL value with length 0, name must have length */
142 if(!dynhds || !name || !namelen || (!value && valuelen)) {
143 DEBUGASSERT(0);
144 return CURLE_BAD_FUNCTION_ARGUMENT;
145 }
146 /* Does the new header fit into the limits? */
147 if((dynhds->max_entries && (dynhds->hds_len >= dynhds->max_entries)) ||
148 (dynhds->max_strs_size - dynhds->strs_len < namelen) ||
149 (dynhds->max_strs_size - dynhds->strs_len - namelen < valuelen))
150 return CURLE_OUT_OF_MEMORY;
152 entry = entry_new(name, namelen, value, valuelen, dynhds->opts);
153 if(!entry)
154 goto out;
156 if(dynhds->hds_len + 1 >= dynhds->hds_allc) {
157 size_t nallc = dynhds->hds_allc ? dynhds->hds_allc * 2 : 16;
158 struct dynhds_entry **nhds;
160 if(dynhds->max_entries && nallc > dynhds->max_entries)
161 nallc = dynhds->max_entries;
163 nhds = curlx_calloc(nallc, sizeof(struct dynhds_entry *));
164 if(!nhds)
165 goto out;
166 if(dynhds->hds) {
167 memcpy(nhds, dynhds->hds,
168 dynhds->hds_len * sizeof(struct dynhds_entry *));
169 curlx_safefree(dynhds->hds);
170 }
171 dynhds->hds = nhds;
172 dynhds->hds_allc = nallc;
173 }
174 dynhds->hds[dynhds->hds_len++] = entry;
175 entry = NULL;
176 dynhds->strs_len += namelen + valuelen;
177 result = CURLE_OK;
179out:
180 if(entry)
181 entry_free(entry);
182 return result;
185CURLcode Curl_dynhds_cadd(struct dynhds *dynhds,
186 const char *name, const char *value)
188 if(!name)
189 return CURLE_BAD_FUNCTION_ARGUMENT;
190 return Curl_dynhds_add(dynhds, name, strlen(name),
191 value, value ? strlen(value) : 0);
194CURLcode Curl_dynhds_h1_add_line(struct dynhds *dynhds,
195 const char *line, size_t line_len)
197 const char *p;
198 const char *name;
199 size_t namelen;
200 const char *value;
201 size_t valuelen, i;
203 if(!line || !line_len)
204 return CURLE_OK;
206 p = memchr(line, ':', line_len);
207 if(!p || p == line)
208 return CURLE_BAD_FUNCTION_ARGUMENT;
209 name = line;
210 namelen = p - line;
211 p++; /* move past the colon */
212 for(i = namelen + 1; i < line_len; ++i, ++p) {
213 if(!ISBLANK(*p))
214 break;
215 }
216 value = p;
217 valuelen = line_len - i;
219 p = memchr(value, '\r', valuelen);
220 if(!p)
221 p = memchr(value, '\n', valuelen);
222 if(p)
223 valuelen = (size_t)(p - value);
225 return Curl_dynhds_add(dynhds, name, namelen, value, valuelen);
228CURLcode Curl_dynhds_h1_cadd_line(struct dynhds *dynhds, const char *line)
230 return Curl_dynhds_h1_add_line(dynhds, line, line ? strlen(line) : 0);
233#ifdef UNITTESTS
234/* @unittest 2602 */
236/**
237 * Return TRUE iff one or more headers with the given name exist.
238 */
239UNITTEST bool dynhds_contains(struct dynhds *dynhds,
240 const char *name, size_t namelen);
241UNITTEST bool dynhds_contains(struct dynhds *dynhds,
242 const char *name, size_t namelen)
244 return !!Curl_dynhds_get(dynhds, name, namelen);
247/* @unittest 2602 */
248UNITTEST bool dynhds_ccontains(struct dynhds *dynhds, const char *name);
249UNITTEST bool dynhds_ccontains(struct dynhds *dynhds, const char *name)
251 return dynhds_contains(dynhds, name, strlen(name));
254/**
255 * Return how often the given name appears in `dynhds`.
256 * Names are case-insensitive.
257 *
258 * @unittest 2602
259 */
260UNITTEST size_t dynhds_count_name(struct dynhds *dynhds,
261 const char *name, size_t namelen);
262UNITTEST size_t dynhds_count_name(struct dynhds *dynhds,
263 const char *name, size_t namelen)
265 size_t n = 0;
266 if(dynhds->hds_len) {
267 size_t i;
268 for(i = 0; i < dynhds->hds_len; ++i) {
269 if((namelen == dynhds->hds[i]->namelen) &&
270 curl_strnequal(name, dynhds->hds[i]->name, namelen))
271 ++n;
272 }
273 }
274 return n;
277/**
278 * Return how often the given null-terminated name appears in `dynhds`.
279 * Names are case-insensitive.
280 *
281 * @unittest 2602
282 */
283UNITTEST size_t dynhds_ccount_name(struct dynhds *dynhds,
284 const char *name);
285UNITTEST size_t dynhds_ccount_name(struct dynhds *dynhds,
286 const char *name)
288 return dynhds_count_name(dynhds, name, strlen(name));
291/**
292 * Remove all entries with the given name.
293 * Returns number of entries removed.
294 *
295 * @unittest 2602
296 */
297UNITTEST size_t dynhds_remove(struct dynhds *dynhds,
298 const char *name, size_t namelen);
299UNITTEST size_t dynhds_remove(struct dynhds *dynhds,
300 const char *name, size_t namelen)
302 size_t n = 0;
303 if(dynhds->hds_len) {
304 size_t i, len;
305 for(i = 0; i < dynhds->hds_len; ++i) {
306 if((namelen == dynhds->hds[i]->namelen) &&
307 curl_strnequal(name, dynhds->hds[i]->name, namelen)) {
308 ++n;
309 --dynhds->hds_len;
310 dynhds->strs_len -= (dynhds->hds[i]->namelen +
311 dynhds->hds[i]->valuelen);
312 entry_free(dynhds->hds[i]);
313 len = dynhds->hds_len - i; /* remaining entries */
314 if(len) {
315 memmove(&dynhds->hds[i], &dynhds->hds[i + 1],
316 len * sizeof(dynhds->hds[i]));
317 }
318 --i; /* do this index again */
319 }
320 }
321 }
322 return n;
325/**
326 * Set the give header name and value, replacing any entries with
327 * the same name. The header is added at the end of all (remaining)
328 * entries.
329 *
330 * @unittest 2602
331 */
332UNITTEST CURLcode dynhds_set(struct dynhds *dynhds,
333 const char *name, size_t namelen,
334 const char *value, size_t valuelen);
335UNITTEST CURLcode dynhds_set(struct dynhds *dynhds,
336 const char *name, size_t namelen,
337 const char *value, size_t valuelen)
339 dynhds_remove(dynhds, name, namelen);
340 return Curl_dynhds_add(dynhds, name, namelen, value, valuelen);
343/* @unittest 2602 */
344UNITTEST size_t dynhds_cremove(struct dynhds *dynhds, const char *name);
345UNITTEST size_t dynhds_cremove(struct dynhds *dynhds, const char *name)
347 return dynhds_remove(dynhds, name, strlen(name));
350#endif /* UNITTESTS */
352CURLcode Curl_dynhds_h1_dprint(struct dynhds *dynhds, struct dynbuf *dbuf)
354 CURLcode result = CURLE_OK;
355 size_t i;
357 if(!dynhds->hds_len)
358 return result;
360 for(i = 0; i < dynhds->hds_len; ++i) {
361 result = curlx_dyn_addn(dbuf, dynhds->hds[i]->name,
362 dynhds->hds[i]->namelen);
363 if(!result)
364 result = curlx_dyn_addn(dbuf, STRCONST(": "));
365 if(!result)
366 result = curlx_dyn_addn(dbuf, dynhds->hds[i]->value,
367 dynhds->hds[i]->valuelen);
368 if(!result)
369 result = curlx_dyn_addn(dbuf, STRCONST("\r\n"));
370 if(result)
371 break;
372 }
374 return result;
377#ifdef USE_NGHTTP2
379nghttp2_nv *Curl_dynhds_to_nva(struct dynhds *dynhds, size_t *pcount)
381 nghttp2_nv *nva = curlx_calloc(1, sizeof(nghttp2_nv) * dynhds->hds_len);
382 size_t i;
384 *pcount = 0;
385 if(!nva)
386 return NULL;
388 for(i = 0; i < dynhds->hds_len; ++i) {
389 struct dynhds_entry *e = dynhds->hds[i];
390 DEBUGASSERT(e);
391 nva[i].name = (unsigned char *)e->name;
392 nva[i].namelen = e->namelen;
393 nva[i].value = (unsigned char *)e->value;
394 nva[i].valuelen = e->valuelen;
395 nva[i].flags = NGHTTP2_NV_FLAG_NONE;
396 }
397 *pcount = dynhds->hds_len;
398 return nva;
401#endif /* USE_NGHTTP2 */
Diagnostics4 git calls · 112 ms
CallStatusSizeTime0112 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=2
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
fetch2003.0 KiB107 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=106
git.response.bytes=3118
git.response.cache=MISS
git.response.duration_ms=107
git.fetch.wants=c3aad4b503f8d1fce4799ef185c368c485a5a0e1
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=3118
git.pkt.payload.max=3097
git.sideband.band1.bytes=3096
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
a5e2d2c43d13cf3a
Request
5e91c5de…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format