mirror of
https://github.com/curl/curl.git
synced 2026-04-11 12:01:42 +08:00
alt-svc: skip expired entries read from file
Extend test 1654 to verify Closes #21187
This commit is contained in:
parent
4478a10f0d
commit
11609c3d45
58
lib/altsvc.c
58
lib/altsvc.c
@ -45,6 +45,24 @@
|
||||
|
||||
#define H3VERSION "h3"
|
||||
|
||||
#if defined(DEBUGBUILD) || defined(UNITTESTS)
|
||||
/* to play well with debug builds, we can *set* a fixed time this will
|
||||
return */
|
||||
static time_t altsvc_debugtime(void *unused)
|
||||
{
|
||||
const char *timestr = getenv("CURL_TIME");
|
||||
(void)unused;
|
||||
if(timestr) {
|
||||
curl_off_t val;
|
||||
curlx_str_number(×tr, &val, TIME_T_MAX);
|
||||
return (time_t)val;
|
||||
}
|
||||
return time(NULL);
|
||||
}
|
||||
#undef time
|
||||
#define time(x) altsvc_debugtime(x)
|
||||
#endif
|
||||
|
||||
/* Given the ALPN ID, return the name */
|
||||
const char *Curl_alpnid2str(enum alpnid id)
|
||||
{
|
||||
@ -165,22 +183,26 @@ static CURLcode altsvc_add(struct altsvcinfo *asi, const char *line)
|
||||
struct altsvc *as;
|
||||
char dbuf[MAX_ALTSVC_DATELEN + 1];
|
||||
time_t expires = 0;
|
||||
time_t now = time(NULL);
|
||||
|
||||
/* The date parser works on a null-terminated string. The maximum length
|
||||
is upheld by curlx_str_quotedword(). */
|
||||
memcpy(dbuf, curlx_str(&date), curlx_strlen(&date));
|
||||
dbuf[curlx_strlen(&date)] = 0;
|
||||
Curl_getdate_capped(dbuf, &expires);
|
||||
as = altsvc_create(&srchost, &dsthost, &srcalpn, &dstalpn,
|
||||
(size_t)srcport, (size_t)dstport);
|
||||
if(as) {
|
||||
as->expires = expires;
|
||||
as->prio = 0; /* not supported, set zero */
|
||||
as->persist = persist ? 1 : 0;
|
||||
Curl_llist_append(&asi->list, as, &as->node);
|
||||
|
||||
if(now < expires) {
|
||||
as = altsvc_create(&srchost, &dsthost, &srcalpn, &dstalpn,
|
||||
(size_t)srcport, (size_t)dstport);
|
||||
if(as) {
|
||||
as->expires = expires;
|
||||
as->prio = 0; /* not supported, set zero */
|
||||
as->persist = persist ? 1 : 0;
|
||||
Curl_llist_append(&asi->list, as, &as->node);
|
||||
}
|
||||
else
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
return CURLE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return CURLE_OK;
|
||||
@ -430,24 +452,6 @@ static void altsvc_flush(struct altsvcinfo *asi, enum alpnid srcalpnid,
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(DEBUGBUILD) || defined(UNITTESTS)
|
||||
/* to play well with debug builds, we can *set* a fixed time this will
|
||||
return */
|
||||
static time_t altsvc_debugtime(void *unused)
|
||||
{
|
||||
const char *timestr = getenv("CURL_TIME");
|
||||
(void)unused;
|
||||
if(timestr) {
|
||||
curl_off_t val;
|
||||
curlx_str_number(×tr, &val, TIME_T_MAX);
|
||||
return (time_t)val;
|
||||
}
|
||||
return time(NULL);
|
||||
}
|
||||
#undef time
|
||||
#define time(x) altsvc_debugtime(x)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Curl_altsvc_parse() takes an incoming alt-svc response header and stores
|
||||
* the data correctly in the cache.
|
||||
|
||||
@ -25,10 +25,11 @@ alt-svc
|
||||
</command>
|
||||
<file name="%LOGDIR/%TESTNUMBER" mode="text">
|
||||
h2 example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 0
|
||||
h2 expired.com 443 h3 shiny.example.com 8443 "20190122 00:00:00" 0 0
|
||||
# a comment
|
||||
h2 foo.example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 0
|
||||
h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 0
|
||||
%TABh3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 0
|
||||
h1 example.com 443 h3 shiny.example.com 8443 "20221231 00:00:01" 0 0
|
||||
%TABh3 example.com 443 h3 shiny.example.com 8443 "20231231 00:00:00" 0 0
|
||||
# also a comment
|
||||
bad example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 0
|
||||
rubbish
|
||||
@ -40,8 +41,8 @@ rubbish
|
||||
# This file was generated by libcurl! Edit at your own risk.
|
||||
h2 example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 0
|
||||
h2 foo.example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 0
|
||||
h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 0
|
||||
h3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 0
|
||||
h1 example.com 443 h3 shiny.example.com 8443 "20221231 00:00:01" 0 0
|
||||
h3 example.com 443 h3 shiny.example.com 8443 "20231231 00:00:00" 0 0
|
||||
h1 example.org 8080 h2 example.com 8080 "20190125 22:34:21" 0 0
|
||||
h1 2.example.org 8080 h3 2.example.org 8080 "20190125 22:34:21" 0 0
|
||||
h1 3.example.org 8080 h2 example.com 8080 "20190125 22:34:21" 0 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user