alt-svc: the libcurl bits

This commit is contained in:
Daniel Stenberg 2019-03-03 11:17:52 +01:00
parent 4331a3b8fa
commit e1be825453
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
25 changed files with 1180 additions and 32 deletions

View file

@ -249,6 +249,7 @@ unittest
unix-sockets
WinSSL
ld_preload
alt-svc
as well as each protocol that curl supports. A protocol only needs to be
specified if it is different from the server (useful when the server

View file

@ -183,7 +183,7 @@ test1590 test1591 test1592 \
test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \
test1608 test1609 test1620 test1621 \
\
test1650 test1651 test1652 test1653 \
test1650 test1651 test1652 test1653 test1654 \
\
test1700 test1701 test1702 \
\

57
tests/data/test1654 Normal file
View file

@ -0,0 +1,57 @@
<testcase>
<info>
<keywords>
unittest
alt-svc
altsvc
</keywords>
</info>
<client>
<server>
none
</server>
<features>
unittest
alt-svc
</features>
# This date is exactly "20190124 22:34:21" UTC
<setenv>
CURL_TIME=1548369261
</setenv>
<name>
alt-svc
</name>
<command>
log/1654
</command>
<tool>
unit1654
</tool>
<file name="log/1654" mode="text">
h2 example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 1
# a comment
h2c example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 1
h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 1
h3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 1
# also a comment
bad example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 1
rubbish
</file>
</client>
<verify>
<file name="log/1654-out" mode="text">
# Your alt-svc cache. https://curl.haxx.se/docs/alt-svc.html
# 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 1
h2c example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 1
h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 1
h3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 1
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
h1 3.example.org 8080 h3 yesyes.com 8080 "20190125 22:34:21" 0 0
h2c example.org 80 h2 example.com 443 "20190124 22:36:21" 0 0
</verify>
</testcase>

View file

@ -233,6 +233,7 @@ my $has_crypto; # set if libcurl is built with cryptographic support
my $has_cares; # set if built with c-ares
my $has_threadedres;# set if built with threaded resolver
my $has_psl; # set if libcurl is built with PSL support
my $has_altsvc; # set if libcurl is built with alt-svc support
my $has_ldpreload; # set if curl is built for systems supporting LD_PRELOAD
my $has_multissl; # set if curl is build with MultiSSL support
my $has_manual; # set if curl is built with built-in manual
@ -2838,6 +2839,10 @@ sub checksystem {
# PSL enabled
$has_psl=1;
}
if($feat =~ /alt-svc/i) {
# alt-svc enabled
$has_altsvc=1;
}
if($feat =~ /AsynchDNS/i) {
if(!$has_cares) {
# this means threaded resolver
@ -3387,6 +3392,11 @@ sub singletest {
next;
}
}
elsif($1 eq "alt-svc") {
if($has_altsvc) {
next;
}
}
elsif($1 eq "manual") {
if($has_manual) {
next;

View file

@ -11,7 +11,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
unit1399 \
unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \
unit1608 unit1609 unit1620 unit1621 \
unit1650 unit1651 unit1652 unit1653
unit1650 unit1651 unit1652 unit1653 unit1654
unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1300_CPPFLAGS = $(AM_CPPFLAGS)
@ -115,3 +115,6 @@ unit1652_CPPFLAGS = $(AM_CPPFLAGS)
unit1653_SOURCES = unit1653.c $(UNITFILES)
unit1653_CPPFLAGS = $(AM_CPPFLAGS)
unit1654_SOURCES = unit1654.c $(UNITFILES)
unit1654_CPPFLAGS = $(AM_CPPFLAGS)

124
tests/unit/unit1654.c Normal file
View file

@ -0,0 +1,124 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "urldata.h"
#include "altsvc.h"
static CURLcode
unit_setup(void)
{
return CURLE_OK;
}
static void
unit_stop(void)
{
curl_global_cleanup();
}
#if defined(CURL_DISABLE_HTTP) || !defined(USE_ALTSVC)
UNITTEST_START
{
return 0; /* nothing to do when HTTP is disabled or alt-svc support is
missing */
}
UNITTEST_STOP
#else
UNITTEST_START
{
char outname[256];
CURL *curl;
CURLcode result;
struct altsvcinfo *asi = Curl_altsvc_init();
if(!asi)
return 1;
result = Curl_altsvc_load(asi, arg);
if(result)
return result;
curl = curl_easy_init();
if(!curl)
goto fail;
fail_unless(asi->num == 4, "wrong number of entries");
msnprintf(outname, sizeof(outname), "%s-out", arg);
result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"",
ALPN_h1, "example.org", 8080);
if(result) {
fprintf(stderr, "Curl_altsvc_parse() failed!\n");
unitfail++;
}
fail_unless(asi->num == 5, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"",
ALPN_h1, "2.example.org", 8080);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(2) failed!\n");
unitfail++;
}
fail_unless(asi->num == 6, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.com:8080\", h3=\"yesyes.com\"",
ALPN_h1, "3.example.org", 8080);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(3) failed!\n");
unitfail++;
}
/* that one should make two entries */
fail_unless(asi->num == 8, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:443\"; ma = 120;",
ALPN_h2c, "example.org", 80);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(4) failed!\n");
unitfail++;
}
fail_unless(asi->num == 9, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi,
"h2=\":443\", h3=\":443\"; ma = 120; persist = 1",
ALPN_h1, "curl.haxx.se", 80);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(5) failed!\n");
unitfail++;
}
fail_unless(asi->num == 11, "wrong number of entries");
/* clear that one again and decrease the counter */
result = Curl_altsvc_parse(curl, asi, "clear;",
ALPN_h1, "curl.haxx.se", 80);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(6) failed!\n");
unitfail++;
}
fail_unless(asi->num == 9, "wrong number of entries");
Curl_altsvc_save(asi, outname);
curl_easy_cleanup(curl);
fail:
Curl_altsvc_cleanup(asi);
return unitfail;
}
UNITTEST_STOP
#endif