mirror of
https://github.com/curl/curl.git
synced 2026-07-23 05:57:16 +03:00
url: connection reuse on h3 connections
- When searching for existing connections, interpret the default CURL_HTTP_VERSION_2TLS as "anything goes". This will allow us to reuse HTTP/3 connections better - add 'http/1.1' as allowed protocol identifier in Alt-Svc files - add test_02_0[345] for testing protocol selection on provided alt-svc files Fixes #14890 Reported-by: MacKenzie Closes #14966
This commit is contained in:
parent
c91c37b6e8
commit
433d73033e
3 changed files with 105 additions and 18 deletions
|
|
@ -28,6 +28,7 @@ import difflib
|
|||
import filecmp
|
||||
import logging
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
import pytest
|
||||
|
||||
from testenv import Env, CurlClient
|
||||
|
|
@ -78,3 +79,72 @@ class TestReuse:
|
|||
r.check_response(count=count, http_status=200)
|
||||
# Connections time out on server before we send another request,
|
||||
assert r.total_connects == count
|
||||
|
||||
@pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
|
||||
def test_12_03_alt_svc_h2h3(self, env: Env, httpd, nghttpx):
|
||||
httpd.clear_extra_configs()
|
||||
httpd.reload()
|
||||
count = 2
|
||||
# write a alt-svc file the advises h3 instead of h2
|
||||
asfile = os.path.join(env.gen_dir, 'alt-svc-12_03.txt')
|
||||
ts = datetime.now() + timedelta(hours=24)
|
||||
expires = f'{ts.year:04}{ts.month:02}{ts.day:02} {ts.hour:02}:{ts.minute:02}:{ts.second:02}'
|
||||
with open(asfile, 'w') as fd:
|
||||
fd.write(f'h2 {env.domain1} {env.https_port} h3 {env.domain1} {env.https_port} "{expires}" 0 0')
|
||||
log.info(f'altscv: {open(asfile).readlines()}')
|
||||
curl = CurlClient(env=env)
|
||||
urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json?[0-{count-1}]'
|
||||
r = curl.http_download(urls=[urln], with_stats=True, extra_args=[
|
||||
'--alt-svc', f'{asfile}',
|
||||
])
|
||||
r.check_response(count=count, http_status=200)
|
||||
# We expect the connection to be reused
|
||||
assert r.total_connects == 1
|
||||
for s in r.stats:
|
||||
assert s['http_version'] == '3', f'{s}'
|
||||
|
||||
def test_12_04_alt_svc_h3h2(self, env: Env, httpd, nghttpx):
|
||||
httpd.clear_extra_configs()
|
||||
httpd.reload()
|
||||
count = 2
|
||||
# write a alt-svc file the advises h2 instead of h3
|
||||
asfile = os.path.join(env.gen_dir, 'alt-svc-12_04.txt')
|
||||
ts = datetime.now() + timedelta(hours=24)
|
||||
expires = f'{ts.year:04}{ts.month:02}{ts.day:02} {ts.hour:02}:{ts.minute:02}:{ts.second:02}'
|
||||
with open(asfile, 'w') as fd:
|
||||
fd.write(f'h3 {env.domain1} {env.https_port} h2 {env.domain1} {env.https_port} "{expires}" 0 0')
|
||||
log.info(f'altscv: {open(asfile).readlines()}')
|
||||
curl = CurlClient(env=env)
|
||||
urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json?[0-{count-1}]'
|
||||
r = curl.http_download(urls=[urln], with_stats=True, extra_args=[
|
||||
'--alt-svc', f'{asfile}',
|
||||
])
|
||||
r.check_response(count=count, http_status=200)
|
||||
# We expect the connection to be reused
|
||||
assert r.total_connects == 1
|
||||
for s in r.stats:
|
||||
assert s['http_version'] == '2', f'{s}'
|
||||
|
||||
def test_12_05_alt_svc_h3h1(self, env: Env, httpd, nghttpx):
|
||||
httpd.clear_extra_configs()
|
||||
httpd.reload()
|
||||
count = 2
|
||||
# write a alt-svc file the advises h1 instead of h3
|
||||
asfile = os.path.join(env.gen_dir, 'alt-svc-12_05.txt')
|
||||
ts = datetime.now() + timedelta(hours=24)
|
||||
expires = f'{ts.year:04}{ts.month:02}{ts.day:02} {ts.hour:02}:{ts.minute:02}:{ts.second:02}'
|
||||
with open(asfile, 'w') as fd:
|
||||
fd.write(f'h3 {env.domain1} {env.https_port} http/1.1 {env.domain1} {env.https_port} "{expires}" 0 0')
|
||||
log.info(f'altscv: {open(asfile).readlines()}')
|
||||
curl = CurlClient(env=env)
|
||||
urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json?[0-{count-1}]'
|
||||
r = curl.http_download(urls=[urln], with_stats=True, extra_args=[
|
||||
'--alt-svc', f'{asfile}',
|
||||
])
|
||||
r.check_response(count=count, http_status=200)
|
||||
# We expect the connection to be reused
|
||||
assert r.total_connects == 1
|
||||
# When using http/1.1 from alt-svc, we ALPN-negotiate 'h2,http/1.1' anyway
|
||||
# which means our server gives us h2
|
||||
for s in r.stats:
|
||||
assert s['http_version'] == '2', f'{s}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue