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/*
25 * The Alt-Svc: header is defined in RFC 7838:
26 * https://datatracker.ietf.org/doc/html/rfc7838
27 */
28#include "curl_setup.h"
30#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
31#include "urldata.h"
32#include "altsvc.h"
33#include "curl_fopen.h"
34#include "curl_get_line.h"
35#include "parsedate.h"
36#include "curl_trc.h"
37#include "curlx/inet_pton.h"
38#include "curlx/strparse.h"
39#include "connect.h"
40#include "escape.h"
42#define MAX_ALTSVC_LINE 4095
43#define MAX_ALTSVC_DATELEN 17
44#define MAX_ALTSVC_HOSTLEN 2048
45#define MAX_ALTSVC_ALPNLEN 10
47#define H3VERSION "h3"
49#if defined(DEBUGBUILD) || defined(UNITTESTS)
50/* to play well with debug builds, we can *set* a fixed time this will
51 return */
52static time_t altsvc_debugtime(void *unused)
53{
54 const char *timestr = getenv("CURL_TIME");
55 (void)unused;
56 if(timestr) {
57 curl_off_t val;
58 curlx_str_number(×tr, &val, TIME_T_MAX);
59 return (time_t)val;
60 }
61 return time(NULL);
62}
63#undef time
64#define time(x) altsvc_debugtime(x)
65#endif
67/* Given the ALPN ID, return the name */
68const char *Curl_alpnid2str(enum alpnid id)
69{
70 switch(id) {
71 case ALPN_h1:
72 return "h1";
73 case ALPN_h2:
74 return "h2";
75 case ALPN_h3:
76 return H3VERSION;
77 default:
78 return ""; /* bad */
79 }
80}
82static enum alpnid Curl_str2alpnid(const struct Curl_str *cstr)
83{
84 return Curl_alpn2alpnid((const unsigned char *)curlx_str(cstr),
85 curlx_strlen(cstr));
86}
88#define altsvc_free(x) curlx_free(x)
90static struct altsvc *altsvc_createid(const char *srchost,
91 size_t hlen,
92 const char *dsthost,
93 size_t dlen, /* dsthost length */
94 enum alpnid srcalpnid,
95 enum alpnid dstalpnid,
96 size_t srcport,
97 size_t dstport)
98{
99 struct altsvc *as;
100 if((hlen > 2) && srchost[0] == '[') {
101 /* IPv6 address, strip off brackets */
102 srchost++;
103 hlen -= 2;
104 }
105 else if(hlen && (srchost[hlen - 1] == '.')) {
106 /* strip off trailing dot */
107 hlen--;
108 }
109 if((dlen > 2) && dsthost[0] == '[') {
110 /* IPv6 address, strip off brackets */
111 dsthost++;
112 dlen -= 2;
113 }
114 if(!hlen || !dlen)
115 /* bad input */
116 return NULL;
117 /* struct size plus both strings */
118 as = curlx_calloc(1, sizeof(struct altsvc) + (hlen + 1) + (dlen + 1));
119 if(!as)
120 return NULL;
121 as->src.host = (char *)as + sizeof(struct altsvc);
122 memcpy(as->src.host, srchost, hlen);
123 /* the null-terminator is already there */
125 as->dst.host = (char *)as + sizeof(struct altsvc) + hlen + 1;
126 memcpy(as->dst.host, dsthost, dlen);
127 /* the null-terminator is already there */
129 as->src.alpnid = srcalpnid;
130 as->dst.alpnid = dstalpnid;
131 as->src.port = (unsigned short)srcport;
132 as->dst.port = (unsigned short)dstport;
134 return as;
135}
137static struct altsvc *altsvc_create(struct Curl_str *srchost,
138 struct Curl_str *dsthost,
139 struct Curl_str *srcalpn,
140 struct Curl_str *dstalpn,
141 size_t srcport,
142 size_t dstport)
143{
144 enum alpnid dstalpnid = Curl_str2alpnid(dstalpn);
145 enum alpnid srcalpnid = Curl_str2alpnid(srcalpn);
146 if(!srcalpnid || !dstalpnid)
147 return NULL;
148 return altsvc_createid(curlx_str(srchost), curlx_strlen(srchost),
149 curlx_str(dsthost), curlx_strlen(dsthost),
150 srcalpnid, dstalpnid,
151 srcport, dstport);
152}
154/* append the new entry to the list after possibly removing an old entry
155 first */
156static void altsvc_append(struct altsvcinfo *asi, struct altsvc *as)
157{
158 while(Curl_llist_count(&asi->list) >= MAX_ALTSVC_ENTRIES) {
159 /* It is full. Remove the first entry in the list */
160 struct Curl_llist_node *e = Curl_llist_head(&asi->list);
161 struct altsvc *oldas = Curl_node_elem(e);
162 Curl_node_remove(e);
163 altsvc_free(oldas);
164 }
165 Curl_llist_append(&asi->list, as, &as->node);
166}
168/* only returns SERIOUS errors */
169static CURLcode altsvc_add(struct altsvcinfo *asi, const char *line)
170{
171 /* Example line:
172 h2 example.com 443 h3 shiny.example.com 8443 "20191231 10:00:00" 1
173 */
174 struct Curl_str srchost;
175 struct Curl_str dsthost;
176 struct Curl_str srcalpn;
177 struct Curl_str dstalpn;
178 struct Curl_str date;
179 curl_off_t srcport;
180 curl_off_t dstport;
181 curl_off_t persist;
182 curl_off_t prio;
184 if(curlx_str_word(&line, &srcalpn, MAX_ALTSVC_ALPNLEN) ||
185 curlx_str_singlespace(&line) ||
186 curlx_str_word(&line, &srchost, MAX_ALTSVC_HOSTLEN) ||
187 curlx_str_singlespace(&line) ||
188 curlx_str_number(&line, &srcport, 65535) ||
189 curlx_str_singlespace(&line) ||
190 curlx_str_word(&line, &dstalpn, MAX_ALTSVC_ALPNLEN) ||
191 curlx_str_singlespace(&line) ||
192 curlx_str_word(&line, &dsthost, MAX_ALTSVC_HOSTLEN) ||
193 curlx_str_singlespace(&line) ||
194 curlx_str_number(&line, &dstport, 65535) ||
195 curlx_str_singlespace(&line) ||
196 curlx_str_quotedword(&line, &date, MAX_ALTSVC_DATELEN) ||
197 curlx_str_singlespace(&line) ||
198 curlx_str_number(&line, &persist, 1) ||
199 curlx_str_singlespace(&line) ||
200 curlx_str_number(&line, &prio, 0) ||
201 curlx_str_newline(&line))
202 ;
203 else {
204 char dbuf[MAX_ALTSVC_DATELEN + 1];
205 time_t expires = 0;
206 time_t now = time(NULL);
208 /* The date parser works on a null-terminated string. The maximum length
209 is upheld by curlx_str_quotedword(). */
210 memcpy(dbuf, curlx_str(&date), curlx_strlen(&date));
211 dbuf[curlx_strlen(&date)] = 0;
212 Curl_getdate_capped(dbuf, &expires);
214 if(now < expires) {
215 struct altsvc *as = altsvc_create(&srchost, &dsthost, &srcalpn, &dstalpn,
216 (size_t)srcport, (size_t)dstport);
217 if(as) {
218 as->expires = expires;
219 as->persist = persist ? 1 : 0;
220 altsvc_append(asi, as);
221 }
222 else
223 return CURLE_OUT_OF_MEMORY;
224 }
225 }
227 return CURLE_OK;
228}
230/*
231 * Load alt-svc entries from the given file. The text based line-oriented file
232 * format is documented here: https://curl.se/docs/alt-svc.html
233 *
234 * This function only returns error on major problems that prevent alt-svc
235 * handling to work completely. It will ignore individual syntactical errors
236 * etc.
237 */
238static CURLcode altsvc_load(struct altsvcinfo *asi, const char *file)
239{
240 CURLcode result = CURLE_OK;
241 FILE *fp;
243 /* we need a private copy of the filename so that the altsvc cache file
244 name survives an easy handle reset */
245 curlx_free(asi->filename);
246 asi->filename = curlx_strdup(file);
247 if(!asi->filename)
248 return CURLE_OUT_OF_MEMORY;
250 fp = curlx_fopen(file, FOPEN_READTEXT);
251 if(fp) {
252 curlx_struct_stat stat;
253 if((curlx_fstat(fileno(fp), &stat) == -1) || !S_ISDIR(stat.st_mode)) {
254 bool eof = FALSE;
255 struct dynbuf buf;
256 curlx_dyn_init(&buf, MAX_ALTSVC_LINE);
257 do {
258 result = Curl_get_line(&buf, fp, &eof);
259 if(!result) {
260 const char *lineptr = curlx_dyn_ptr(&buf);
261 curlx_str_passblanks(&lineptr);
262 if(curlx_str_single(&lineptr, '#'))
263 altsvc_add(asi, lineptr);
264 }
265 } while(!result && !eof);
266 curlx_dyn_free(&buf); /* free the line buffer */
267 }
268 curlx_fclose(fp);
269 }
270 return result;
271}
273/*
274 * Write this single altsvc entry to a single output line
275 */
276static CURLcode altsvc_out(struct altsvc *as, FILE *fp)
277{
278 struct tm stamp;
279 const char *dst6_pre = "";
280 const char *dst6_post = "";
281 const char *src6_pre = "";
282 const char *src6_post = "";
283 CURLcode result = curlx_gmtime(as->expires, &stamp);
284 if(result)
285 /* fail silently for date errors so that only this entry gets
286 skipped */
287 return CURLE_OK;
288#ifdef USE_IPV6
289 else {
290 char ipv6_unused[16];
291 if(curlx_inet_pton(AF_INET6, as->dst.host, ipv6_unused) == 1) {
292 dst6_pre = "[";
293 dst6_post = "]";
294 }
295 if(curlx_inet_pton(AF_INET6, as->src.host, ipv6_unused) == 1) {
296 src6_pre = "[";
297 src6_post = "]";
298 }
299 }
300#endif
301 curl_mfprintf(fp,
302 "%s %s%s%s %u "
303 "%s %s%s%s %u "
304 "\"%d%02d%02d "
305 "%02d:%02d:%02d\" "
306 "%d 0\n", /* prio still always zero */
307 Curl_alpnid2str(as->src.alpnid),
308 src6_pre, as->src.host, src6_post,
309 as->src.port,
311 Curl_alpnid2str(as->dst.alpnid),
312 dst6_pre, as->dst.host, dst6_post,
313 as->dst.port,
315 stamp.tm_year + 1900, stamp.tm_mon + 1, stamp.tm_mday,
316 stamp.tm_hour, stamp.tm_min, stamp.tm_sec,
317 as->persist);
318 return CURLE_OK;
319}
321/* ---- library-wide functions below ---- */
323/*
324 * Curl_altsvc_init() creates a new altsvc cache.
325 * It returns the new instance or NULL if something goes wrong.
326 */
327struct altsvcinfo *Curl_altsvc_init(void)
328{
329 struct altsvcinfo *asi = curlx_calloc(1, sizeof(struct altsvcinfo));
330 if(!asi)
331 return NULL;
332 Curl_llist_init(&asi->list, NULL);
334 /* set default behavior */
335 asi->flags = CURLALTSVC_H1
336#ifdef USE_HTTP2
337 | CURLALTSVC_H2
338#endif
339#ifdef USE_HTTP3
340 | CURLALTSVC_H3
341#endif
342 ;
343 return asi;
344}
346/*
347 * Curl_altsvc_load() loads alt-svc from file.
348 */
349CURLcode Curl_altsvc_load(struct altsvcinfo *asi, const char *file)
350{
351 DEBUGASSERT(asi);
352 return altsvc_load(asi, file);
353}
355/*
356 * Curl_altsvc_ctrl() passes on the external bitmask.
357 */
358CURLcode Curl_altsvc_ctrl(struct Curl_easy *data, const long ctrl)
359{
360 DEBUGASSERT(data);
361 if(!ctrl)
362 return CURLE_BAD_FUNCTION_ARGUMENT;
364 if(!data->asi) {
365 data->asi = Curl_altsvc_init();
366 if(!data->asi)
367 return CURLE_OUT_OF_MEMORY;
368 }
369 data->asi->flags = ctrl;
370 return CURLE_OK;
371}
373/*
374 * Curl_altsvc_cleanup() frees an altsvc cache instance and all associated
375 * resources.
376 */
377void Curl_altsvc_cleanup(struct altsvcinfo **asi)
378{
379 if(*asi) {
380 struct Curl_llist_node *e;
381 struct Curl_llist_node *n;
382 struct altsvcinfo *altsvc = *asi;
383 for(e = Curl_llist_head(&altsvc->list); e; e = n) {
384 struct altsvc *as = Curl_node_elem(e);
385 n = Curl_node_next(e);
386 altsvc_free(as);
387 }
388 curlx_free(altsvc->filename);
389 curlx_free(altsvc);
390 *asi = NULL; /* clear the pointer */
391 }
392}
394/*
395 * Curl_altsvc_save() writes the altsvc cache to a file.
396 */
397CURLcode Curl_altsvc_save(struct Curl_easy *data,
398 struct altsvcinfo *asi, const char *file)
399{
400 CURLcode result = CURLE_OK;
401 FILE *out;
402 char *tempstore = NULL;
404 if(!asi)
405 /* no cache activated */
406 return CURLE_OK;
408 /* if not new name is given, use the one we stored from the load */
409 if(!file && asi->filename)
410 file = asi->filename;
412 if((asi->flags & CURLALTSVC_READONLYFILE) || !file || !file[0])
413 /* marked as read-only, no file or zero length filename */
414 return CURLE_OK;
416 result = Curl_fopen(data, file, &out, &tempstore);
417 if(!result) {
418 struct Curl_llist_node *e;
419 struct Curl_llist_node *n;
420 fputs("# Your alt-svc cache. https://curl.se/docs/alt-svc.html\n"
421 "# This file was generated by libcurl! Edit at your own risk.\n",
422 out);
423 for(e = Curl_llist_head(&asi->list); e; e = n) {
424 struct altsvc *as = Curl_node_elem(e);
425 n = Curl_node_next(e);
426 result = altsvc_out(as, out);
427 if(result)
428 break;
429 }
430 curlx_fclose(out);
431 if(!result && tempstore && curlx_rename(tempstore, file))
432 result = CURLE_WRITE_ERROR;
434 if(result && tempstore)
435 unlink(tempstore);
436 }
437 curlx_free(tempstore);
438 return result;
439}
441/* hostcompare() returns true if 'host' matches 'check'. The first host
442 * argument may have a trailing dot present that will be ignored.
443 */
444static bool hostcompare(const char *host, const char *check)
445{
446 size_t hlen = strlen(host);
447 size_t clen = strlen(check);
449 if(hlen && (host[hlen - 1] == '.'))
450 hlen--;
451 if(hlen != clen)
452 /* they cannot match if they have different lengths */
453 return FALSE;
454 return curl_strnequal(host, check, hlen);
455}
457/* altsvc_flush() removes all alternatives for this source origin from the
458 list */
459static void altsvc_flush(struct altsvcinfo *asi,
460 struct Curl_peer *origin,
461 enum alpnid origin_alpnid)
462{
463 struct Curl_llist_node *e;
464 struct Curl_llist_node *n;
465 for(e = Curl_llist_head(&asi->list); e; e = n) {
466 struct altsvc *as = Curl_node_elem(e);
467 n = Curl_node_next(e);
468 if((origin_alpnid == as->src.alpnid) &&
469 (origin->port == as->src.port) &&
470 hostcompare(origin->hostname, as->src.host)) {
471 Curl_node_remove(e);
472 altsvc_free(as);
473 }
474 }
475}
477#define CAP_ALTSVC_MAX_AGE (2*365*24*3600) /* two years cap */
479#define ALTSVC_MA 1
480#define ALTSVC_PERSIST 2
481static void altsvc_parse_params(const char **pp,
482 time_t *pmaxage,
483 bool *ppersist)
484{
485 curlx_str_passblanks(pp);
486 if(curlx_str_single(pp, ';'))
487 return;
489 for(;;) {
490 struct Curl_str name;
491 struct Curl_str val;
492 curl_off_t num;
493 int keyword = 0;
495 /* allow some extra whitespaces around name and value */
496 if(curlx_str_until(pp, &name, MAX_ALTSVC_LINE, '=') ||
497 curlx_str_single(pp, '='))
498 break; /* skip further parameter parsing */
500 curlx_str_trimblanks(&name);
501 curlx_str_passblanks(pp);
502 if(**pp == '\"') {
503 if(curlx_str_quotedword(pp, &val, MAX_ALTSVC_LINE))
504 break;
505 }
506 else {
507 if(curlx_str_cspn(pp, &val, ",;\r\n"))
508 break;
509 }
510 curlx_str_trimblanks(&val);
512 if(curlx_str_casecompare(&name, "ma"))
513 keyword = ALTSVC_MA;
514 else if(curlx_str_casecompare(&name, "persist"))
515 keyword = ALTSVC_PERSIST;
517 if(keyword) {
518 const char *vp = curlx_str(&val);
519 const char *vend = vp + curlx_strlen(&val);
520 if(curlx_str_number(&vp, &num, CURL_OFF_T_MAX))
521 break; /* not a number, skip further parameter parsing */
522 if(vp != vend)
523 break; /* not entirely a number, skip further parameter parsing */
524 if(keyword == ALTSVC_MA) {
525 if(num > CAP_ALTSVC_MAX_AGE)
526 num = CAP_ALTSVC_MAX_AGE;
527 *pmaxage = (time_t)num;
528 }
529 else if(num == 1)
530 *ppersist = TRUE;
531 }
533 curlx_str_passblanks(pp);
534 if(curlx_str_single(pp, ';'))
535 break; /* no further parameters */
536 }
537}
539static bool altsvc_parse_dest(const char **pp,
540 struct Curl_easy *data,
541 struct Curl_peer *origin,
542 struct Curl_str *dsthost,
543 uint16_t *pdstport)
544{
545 curl_off_t port = 0;
547 if(curlx_str_single(pp, '\"'))
548 return FALSE;
550 /* quoted string, with hostname or just :port ? */
551 if(curlx_str_single(pp, ':')) { /* is hostname:port ? */
552 if(curlx_str_single(pp, '[')) { /* DNS hostname/IPv4 */
553 if(curlx_str_until(pp, dsthost, MAX_ALTSVC_HOSTLEN, ':')) {
554 infof(data, "Bad alt-svc hostname, ignoring.");
555 return FALSE;
556 }
557 }
558 else { /* IPv6 hostname */
559 if(curlx_str_until(pp, dsthost, MAX_IPADR_LEN, ']') ||
560 curlx_str_single(pp, ']')) {
561 infof(data, "Bad alt-svc IPv6 hostname, ignoring.");
562 return FALSE;
563 }
564 }
565 if(curlx_str_single(pp, ':'))
566 return FALSE; /* not followed by ':' */
567 }
568 else /* is only :port, hostname is effectively origin */
569 curlx_str_assign(dsthost, origin->hostname,
570 strlen(origin->hostname));
572 if(curlx_str_number(pp, &port, 0xffff)) {
573 infof(data, "Unknown alt-svc port number, ignoring.");
574 return FALSE;
575 }
577 *pdstport = (uint16_t)port;
578 if(curlx_str_single(pp, '\"'))
579 return FALSE; /* quoted string not ending here as expected */
580 return TRUE;
581}
583/*
584 * Curl_altsvc_parse() takes an incoming alt-svc response header and stores
585 * the data correctly in the cache.
586 *
587 * 'value' points to the header *value*. That is contents to the right of the
588 * header name.
589 *
590 * Currently this function rejects invalid data without returning an error.
591 * Invalid hostname, port number will result in the specific alternative
592 * being rejected. Unknown protocols are skipped.
593 */
594CURLcode Curl_altsvc_parse(struct Curl_easy *data,
595 struct altsvcinfo *asi, const char *value,
596 struct Curl_peer *origin,
597 enum alpnid origin_alpnid)
598{
599 struct altsvc *as;
600 size_t entries = 0;
601 struct Curl_str alpn;
602 const char *p;
604 DEBUGASSERT(asi);
605 DEBUGASSERT(origin);
606 /* RFC 7838, The "Alt-Svc" header field value is basically
607 * Alt-Svc: (clear|alpn="(host)?:port"\s*(;\s*parameter=value)*)
608 * This can be repeated, comma-separated.
609 *
610 * We parse "best effort", ignoring values we do not recognize.
611 */
613 /* Try to catch a standalone "clear" */
614 p = value;
615 if(!curlx_str_cspn(&p, &alpn, ";\n\r")) {
616 curlx_str_trimblanks(&alpn);
617 /* "clear" is a magic keyword */
618 if(curlx_str_casecompare(&alpn, "clear")) {
619 /* Flush cached alternatives for this source origin */
620 altsvc_flush(asi, origin, origin_alpnid);
621 return CURLE_OK;
622 }
623 }
625 /* Not a standalone "clear", parse from start for alpn entries */
626 for(p = value; *p;) {
627 time_t maxage = 24 * 3600; /* default is 24 hours */
628 bool persist = FALSE;
629 enum alpnid dstalpnid;
630 struct Curl_str dsthost;
631 uint16_t dstport;
633 if(curlx_str_until(&p, &alpn, MAX_ALTSVC_LINE, '='))
634 break; /* not another entry, leave */
635 curlx_str_trimblanks(&alpn);
636 if(memchr(curlx_str(&alpn), '%', curlx_strlen(&alpn))) {
637 char *decoded;
638 size_t dlen;
639 /* RFC 7838 section 3: protocol-id is a percent-encoded ALPN name. */
640 CURLcode result = Curl_urldecode(curlx_str(&alpn), curlx_strlen(&alpn),
641 &decoded, &dlen, REJECT_CTRL);
642 if(result == CURLE_URL_MALFORMAT)
643 dstalpnid = ALPN_none;
644 else if(result)
645 return result;
646 else {
647 dstalpnid = Curl_alpn2alpnid((const unsigned char *)decoded, dlen);
648 curlx_free(decoded);
649 }
650 }
651 else
652 dstalpnid = Curl_str2alpnid(&alpn);
654 if(curlx_str_single(&p, '='))
655 break;
657 /* Parse altsvc hostname:port */
658 if(!altsvc_parse_dest(&p, data, origin, &dsthost, &dstport))
659 break;
661 /* Parse optional parameters */
662 altsvc_parse_params(&p, &maxage, &persist);
664 if(dstalpnid) { /* this is a known ALPN id, e.g. not ALPN_none */
665 if(!entries++)
666 /* Flush cached alternatives for this source origin, if any - when
667 this is the first entry of the line. */
668 altsvc_flush(asi, origin, origin_alpnid);
670 as = altsvc_createid(origin->hostname, strlen(origin->hostname),
671 curlx_str(&dsthost),
672 curlx_strlen(&dsthost),
673 origin_alpnid, dstalpnid,
674 origin->port, dstport);
675 if(as) {
676 time_t secs = time(NULL);
677 /* The expires time also needs to take the Age: value (if any)
678 into account. [See RFC 7838 section 3.1] */
679 if(maxage > (TIME_T_MAX - secs))
680 as->expires = TIME_T_MAX;
681 else
682 as->expires = maxage + secs;
683 as->persist = persist;
684 altsvc_append(asi, as);
685 infof(data, "Added alt-svc: %.*s:%u over %s",
686 (int)curlx_strlen(&dsthost), curlx_str(&dsthost),
687 dstport, Curl_alpnid2str(dstalpnid));
688 }
689 else
690 return CURLE_OUT_OF_MEMORY;
691 }
693 /* When this is followed by a comma, we expect another entry */
694 if(curlx_str_single(&p, ','))
695 break;
696 }
698 return CURLE_OK;
699}
701/*
702 * Return TRUE on a match
703 */
704bool Curl_altsvc_lookup(struct altsvcinfo *asi,
705 struct Curl_peer *origin,
706 enum alpnid origin_alpnid,
707 struct altsvc **dstentry,
708 const int versions, /* one or more bits */
709 bool *psame_destination)
710{
711 DEBUGASSERT(asi);
712 DEBUGASSERT(origin);
713 DEBUGASSERT(dstentry);
714 *psame_destination = FALSE;
716 if(Curl_llist_count(&asi->list)) {
717 struct Curl_llist_node *e;
718 struct Curl_llist_node *n;
719 time_t now = time(NULL);
721 for(e = Curl_llist_head(&asi->list); e; e = n) {
722 struct altsvc *as = Curl_node_elem(e);
723 n = Curl_node_next(e);
724 if(as->expires < now) {
725 /* an expired entry, remove */
726 Curl_node_remove(e);
727 altsvc_free(as);
728 continue;
729 }
730 if((origin_alpnid == as->src.alpnid) &&
731 (versions & (int)as->dst.alpnid) &&
732 (origin->port == as->src.port) &&
733 hostcompare(origin->hostname, as->src.host)) {
734 /* match */
735 *dstentry = as;
736 /* alt-svc on the same host+port or another one? */
737 *psame_destination = (origin->port == as->dst.port) &&
738 hostcompare(origin->hostname, as->dst.host);
739 return TRUE;
740 }
741 }
742 }
743 return FALSE;
744}
746#if defined(DEBUGBUILD) || defined(UNITTESTS)
747#undef time
748#endif
750#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_ALTSVC */
Diagnostics4 git calls · 46 ms
CallStatusSizeTime046 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 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 · hit22 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=22 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
fetch2007.2 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=7356 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=7e91f04ea7141ccbf2b0c3647d731c45c1a7f8d5 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=7356 git.pkt.payload.max=7335 git.sideband.band1.bytes=7334 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
- a5e2cc66ebb07929
- Request
- aab11eeb…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format