mirror of
https://github.com/curl/curl.git
synced 2026-08-25 22:13:33 +03:00
http2: support HTTP/2 to forward proxies, non-tunneling
- with `--proxy-http2` allow h2 ALPN negotiation to forward proxies - applies to http: requests against a https: proxy only, as https: requests will auto-tunnel - adding a HTTP/1 request parser in http1.c - removed h2h3.c - using new request parser in nghttp2 and all h3 backends - adding test 2603 for request parser - adding h2 proxy test cases to test_10_* scorecard.py: request scoring accidentally always run curl with '-v'. Removed that, expect double numbers. labeller: added http1.* and h2-proxy sources to detection Closes #10967
This commit is contained in:
parent
fb1d62ff07
commit
fc2f1e547a
28 changed files with 1522 additions and 824 deletions
|
|
@ -250,7 +250,7 @@ test2400 test2401 test2402 test2403 \
|
|||
\
|
||||
test2500 test2501 test2502 test2503 \
|
||||
\
|
||||
test2600 test2601 test2602 \
|
||||
test2600 test2601 test2602 test2603 \
|
||||
\
|
||||
test3000 test3001 test3002 test3003 test3004 test3005 test3006 test3007 \
|
||||
test3008 test3009 test3010 test3011 test3012 test3013 test3014 test3015 \
|
||||
|
|
|
|||
22
tests/data/test2603
Normal file
22
tests/data/test2603
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<testcase>
|
||||
<info>
|
||||
<keywords>
|
||||
unittest
|
||||
http1
|
||||
</keywords>
|
||||
</info>
|
||||
|
||||
#
|
||||
# Client-side
|
||||
<client>
|
||||
<server>
|
||||
none
|
||||
</server>
|
||||
<features>
|
||||
unittest
|
||||
</features>
|
||||
<name>
|
||||
http1 parser unit tests
|
||||
</name>
|
||||
</client>
|
||||
</testcase>
|
||||
|
|
@ -281,7 +281,7 @@ class ScoreCard:
|
|||
if max_parallel > 1 else []
|
||||
self.info(f'{max_parallel}...')
|
||||
for i in range(sample_size):
|
||||
curl = CurlClient(env=self.env)
|
||||
curl = CurlClient(env=self.env, silent=self._silent_curl)
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, no_save=True,
|
||||
with_headers=False,
|
||||
extra_args=extra_args)
|
||||
|
|
@ -459,13 +459,11 @@ class ScoreCard:
|
|||
for key, val in sval.items():
|
||||
if 'errors' in val:
|
||||
errors.extend(val['errors'])
|
||||
print(f' {dkey:<8} {skey:>8} '
|
||||
f'{self.fmt_reqs(sval["serial"]["speed"]):>12} '
|
||||
f'{self.fmt_reqs(sval["par-6"]["speed"]):>12} '
|
||||
f'{self.fmt_reqs(sval["par-25"]["speed"]):>12} '
|
||||
f'{self.fmt_reqs(sval["par-50"]["speed"]):>12} '
|
||||
f'{self.fmt_reqs(sval["par-100"]["speed"]):>12} '
|
||||
f' {"/".join(errors):<20}')
|
||||
line = f' {dkey:<8} {skey:>8} '
|
||||
for k in sval.keys():
|
||||
line += f'{self.fmt_reqs(sval[k]["speed"]):>12} '
|
||||
line += f' {"/".join(errors):<20}'
|
||||
print(line)
|
||||
|
||||
|
||||
def parse_size(s):
|
||||
|
|
|
|||
|
|
@ -50,14 +50,6 @@ class TestProxy:
|
|||
httpd.clear_extra_configs()
|
||||
httpd.reload()
|
||||
|
||||
def set_tunnel_proto(self, proto):
|
||||
if proto == 'h2':
|
||||
os.environ['CURL_PROXY_TUNNEL_H2'] = '1'
|
||||
return 'HTTP/2'
|
||||
else:
|
||||
os.environ.pop('CURL_PROXY_TUNNEL_H2', None)
|
||||
return 'HTTP/1.1'
|
||||
|
||||
def get_tunnel_proto_used(self, r: ExecResult):
|
||||
for l in r.trace_lines:
|
||||
m = re.match(r'.* CONNECT tunnel: (\S+) negotiated$', l)
|
||||
|
|
@ -71,37 +63,60 @@ class TestProxy:
|
|||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=curl.get_proxy_args(proxys=False))
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
# download via https: proxy (no tunnel)
|
||||
@pytest.mark.skipif(condition=not Env.curl_has_feature('HTTPS-proxy'),
|
||||
reason='curl lacks HTTPS-proxy support')
|
||||
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
|
||||
@pytest.mark.skipif(condition=not Env.have_nghttpx(), reason="no nghttpx available")
|
||||
def test_10_02_proxy_https(self, env: Env, httpd, nghttpx_fwd, repeat):
|
||||
def test_10_02_proxys_down(self, env: Env, httpd, nghttpx_fwd, proto, repeat):
|
||||
if proto == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proto=proto)
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.proxys_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxys_port}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
r.check_response(count=1, http_status=200)
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
|
||||
# upload via https: with proto (no tunnel)
|
||||
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
|
||||
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
|
||||
@pytest.mark.parametrize("fname, fcount", [
|
||||
['data.json', 5],
|
||||
['data-100k', 5],
|
||||
['data-1m', 2]
|
||||
])
|
||||
@pytest.mark.skipif(condition=not Env.have_nghttpx(),
|
||||
reason="no nghttpx available")
|
||||
def test_10_02_proxys_up(self, env: Env, httpd, nghttpx, proto,
|
||||
fname, fcount, repeat):
|
||||
if proto == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
count = fcount
|
||||
srcfile = os.path.join(httpd.docs_dir, fname)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/curltest/echo?id=[0-{count-1}]'
|
||||
xargs = curl.get_proxy_args(proto=proto)
|
||||
r = curl.http_upload(urls=[url], data=f'@{srcfile}', alpn_proto=proto,
|
||||
extra_args=xargs)
|
||||
r.check_response(count=count, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
indata = open(srcfile).readlines()
|
||||
for i in range(count):
|
||||
respdata = open(curl.response_file(i)).readlines()
|
||||
assert respdata == indata
|
||||
|
||||
# download http: via http: proxytunnel
|
||||
def test_10_03_proxytunnel_http(self, env: Env, httpd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=False, tunnel=True)
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
# download http: via https: proxytunnel
|
||||
|
|
@ -111,13 +126,9 @@ class TestProxy:
|
|||
def test_10_04_proxy_https(self, env: Env, httpd, nghttpx_fwd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(tunnel=True)
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port()}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port()}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
# download https: with proto via http: proxytunnel
|
||||
|
|
@ -126,13 +137,10 @@ class TestProxy:
|
|||
def test_10_05_proxytunnel_http(self, env: Env, httpd, proto, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=False, tunnel=True)
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
|
||||
with_headers=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
|
||||
|
|
@ -145,20 +153,15 @@ class TestProxy:
|
|||
def test_10_06_proxytunnel_https(self, env: Env, httpd, nghttpx_fwd, proto, tunnel, repeat):
|
||||
if tunnel == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/data.json?[0-0]'
|
||||
xargs = curl.get_proxy_args(tunnel=True, proto=tunnel)
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
|
||||
with_headers=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
with_headers=True, extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
assert self.get_tunnel_proto_used(r) == exp_tunnel_proto
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
srcfile = os.path.join(httpd.docs_dir, 'data.json')
|
||||
dfile = curl.download_file(0)
|
||||
assert filecmp.cmp(srcfile, dfile, shallow=False)
|
||||
|
|
@ -178,20 +181,15 @@ class TestProxy:
|
|||
if tunnel == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
count = fcount
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/{fname}?[0-{count-1}]'
|
||||
xargs = curl.get_proxy_args(tunnel=True, proto=tunnel)
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
|
||||
with_headers=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
with_headers=True, extra_args=xargs)
|
||||
r.check_response(count=count, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
assert self.get_tunnel_proto_used(r) == exp_tunnel_proto
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
srcfile = os.path.join(httpd.docs_dir, fname)
|
||||
for i in range(count):
|
||||
dfile = curl.download_file(i)
|
||||
|
|
@ -213,20 +211,15 @@ class TestProxy:
|
|||
pytest.skip('only supported with nghttp2')
|
||||
count = fcount
|
||||
srcfile = os.path.join(httpd.docs_dir, fname)
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/curltest/echo?id=[0-{count-1}]'
|
||||
xargs = curl.get_proxy_args(tunnel=True, proto=tunnel)
|
||||
r = curl.http_upload(urls=[url], data=f'@{srcfile}', alpn_proto=proto,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
assert self.get_tunnel_proto_used(r) == exp_tunnel_proto
|
||||
extra_args=xargs)
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
r.check_response(count=count, http_status=200)
|
||||
indata = open(srcfile).readlines()
|
||||
r.check_response(count=count, http_status=200)
|
||||
for i in range(count):
|
||||
respdata = open(curl.response_file(i)).readlines()
|
||||
assert respdata == indata
|
||||
|
|
@ -237,20 +230,15 @@ class TestProxy:
|
|||
def test_10_09_reuse_ser(self, env: Env, httpd, nghttpx_fwd, tunnel, repeat):
|
||||
if tunnel == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url1 = f'https://localhost:{env.https_port}/data.json'
|
||||
url2 = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(tunnel=True, proto=tunnel)
|
||||
r = curl.http_download(urls=[url1, url2], alpn_proto='http/1.1', with_stats=True,
|
||||
with_headers=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
with_headers=True, extra_args=xargs)
|
||||
r.check_response(count=2, http_status=200)
|
||||
assert self.get_tunnel_proto_used(r) == exp_tunnel_proto
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
if tunnel == 'h2':
|
||||
# TODO: we would like to reuse the first connection for the
|
||||
# second URL, but this is currently not possible
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import re
|
|||
import time
|
||||
import pytest
|
||||
|
||||
from testenv import Env, CurlClient
|
||||
from testenv import Env, CurlClient, ExecResult
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
|
@ -52,20 +52,12 @@ class TestProxyAuth:
|
|||
httpd.set_proxy_auth(False)
|
||||
httpd.reload()
|
||||
|
||||
def set_tunnel_proto(self, proto):
|
||||
if proto == 'h2':
|
||||
os.environ['CURL_PROXY_TUNNEL_H2'] = '1'
|
||||
return 'HTTP/2'
|
||||
else:
|
||||
os.environ.pop('CURL_PROXY_TUNNEL_H2', None)
|
||||
return 'HTTP/1.1'
|
||||
|
||||
def get_tunnel_proto_used(self, curl: CurlClient):
|
||||
assert os.path.exists(curl.trace_file)
|
||||
for l in open(curl.trace_file).readlines():
|
||||
m = re.match(r'.* == Info: CONNECT tunnel: (\S+) negotiated', l)
|
||||
def get_tunnel_proto_used(self, r: ExecResult):
|
||||
for line in r.trace_lines:
|
||||
m = re.match(r'.* CONNECT tunnel: (\S+) negotiated$', line)
|
||||
if m:
|
||||
return m.group(1)
|
||||
assert False, f'tunnel protocol not found in:\n{"".join(r.trace_lines)}'
|
||||
return None
|
||||
|
||||
# download via http: proxy (no tunnel), no auth
|
||||
|
|
@ -73,22 +65,17 @@ class TestProxyAuth:
|
|||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=curl.get_proxy_args(proxys=False))
|
||||
r.check_response(count=1, http_status=407)
|
||||
|
||||
# download via http: proxy (no tunnel), auth
|
||||
def test_13_02_proxy_auth(self, env: Env, httpd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=False)
|
||||
xargs.extend(['--proxy-user', 'proxy:proxy'])
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy-user', 'proxy:proxy',
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
@pytest.mark.skipif(condition=not Env.curl_has_feature('HTTPS-proxy'),
|
||||
|
|
@ -97,12 +84,9 @@ class TestProxyAuth:
|
|||
def test_13_03_proxys_no_auth(self, env: Env, httpd, nghttpx_fwd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=True)
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port()}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port()}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=407)
|
||||
|
||||
@pytest.mark.skipif(condition=not Env.curl_has_feature('HTTPS-proxy'),
|
||||
|
|
@ -111,37 +95,28 @@ class TestProxyAuth:
|
|||
def test_13_04_proxys_auth(self, env: Env, httpd, nghttpx_fwd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=True)
|
||||
xargs.extend(['--proxy-user', 'proxy:proxy'])
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxy-user', 'proxy:proxy',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port()}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port()}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
def test_13_05_tunnel_http_no_auth(self, env: Env, httpd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=False, tunnel=True)
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=xargs)
|
||||
# expect "COULD_NOT_CONNECT"
|
||||
r.check_response(exitcode=56, http_status=None)
|
||||
|
||||
def test_13_06_tunnel_http_auth(self, env: Env, httpd, repeat):
|
||||
curl = CurlClient(env=env)
|
||||
url = f'http://localhost:{env.http_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=False, tunnel=True)
|
||||
xargs.extend(['--proxy-user', 'proxy:proxy'])
|
||||
r = curl.http_download(urls=[url], alpn_proto='http/1.1', with_stats=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy-user', 'proxy:proxy',
|
||||
'--proxy', f'http://{env.proxy_domain}:{env.proxy_port}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.proxy_port}:127.0.0.1',
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200)
|
||||
|
||||
@pytest.mark.skipif(condition=not Env.have_nghttpx(), reason="no nghttpx available")
|
||||
|
|
@ -152,20 +127,16 @@ class TestProxyAuth:
|
|||
def test_13_07_tunnels_no_auth(self, env: Env, httpd, proto, tunnel, repeat):
|
||||
if tunnel == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=True, tunnel=True, proto=tunnel)
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
|
||||
with_headers=True, with_trace=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
extra_args=xargs)
|
||||
# expect "COULD_NOT_CONNECT"
|
||||
r.check_response(exitcode=56, http_status=None)
|
||||
assert self.get_tunnel_proto_used(curl) == exp_tunnel_proto
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
|
||||
@pytest.mark.skipif(condition=not Env.have_nghttpx(), reason="no nghttpx available")
|
||||
@pytest.mark.skipif(condition=not Env.curl_has_feature('HTTPS-proxy'),
|
||||
|
|
@ -175,19 +146,15 @@ class TestProxyAuth:
|
|||
def test_13_08_tunnels_auth(self, env: Env, httpd, proto, tunnel, repeat):
|
||||
if tunnel == 'h2' and not env.curl_uses_lib('nghttp2'):
|
||||
pytest.skip('only supported with nghttp2')
|
||||
exp_tunnel_proto = self.set_tunnel_proto(tunnel)
|
||||
curl = CurlClient(env=env)
|
||||
url = f'https://localhost:{env.https_port}/data.json'
|
||||
xargs = curl.get_proxy_args(proxys=True, tunnel=True, proto=tunnel)
|
||||
xargs.extend(['--proxy-user', 'proxy:proxy'])
|
||||
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
|
||||
with_headers=True, with_trace=True,
|
||||
extra_args=[
|
||||
'--proxytunnel',
|
||||
'--proxy-user', 'proxy:proxy',
|
||||
'--proxy', f'https://{env.proxy_domain}:{env.pts_port(tunnel)}/',
|
||||
'--resolve', f'{env.proxy_domain}:{env.pts_port(tunnel)}:127.0.0.1',
|
||||
'--proxy-cacert', env.ca.cert_file,
|
||||
])
|
||||
extra_args=xargs)
|
||||
r.check_response(count=1, http_status=200,
|
||||
protocol='HTTP/2' if proto == 'h2' else 'HTTP/1.1')
|
||||
assert self.get_tunnel_proto_used(curl) == exp_tunnel_proto
|
||||
assert self.get_tunnel_proto_used(r) == 'HTTP/2' \
|
||||
if tunnel == 'h2' else 'HTTP/1.1'
|
||||
|
||||
|
|
|
|||
|
|
@ -317,6 +317,26 @@ class CurlClient:
|
|||
if not os.path.exists(path):
|
||||
return os.makedirs(path)
|
||||
|
||||
def get_proxy_args(self, proto: str = 'http/1.1',
|
||||
proxys: bool = True, tunnel: bool = False):
|
||||
if proxys:
|
||||
pport = self.env.pts_port(proto) if tunnel else self.env.proxys_port
|
||||
xargs = [
|
||||
'--proxy', f'https://{self.env.proxy_domain}:{pport}/',
|
||||
'--resolve', f'{self.env.proxy_domain}:{pport}:127.0.0.1',
|
||||
'--proxy-cacert', self.env.ca.cert_file,
|
||||
]
|
||||
if proto == 'h2':
|
||||
xargs.append('--proxy-http2')
|
||||
else:
|
||||
xargs = [
|
||||
'--proxy', f'http://{self.env.proxy_domain}:{self.env.proxy_port}/',
|
||||
'--resolve', f'{self.env.proxy_domain}:{self.env.proxy_port}:127.0.0.1',
|
||||
]
|
||||
if tunnel:
|
||||
xargs.append('--proxytunnel')
|
||||
return xargs
|
||||
|
||||
def http_get(self, url: str, extra_args: Optional[List[str]] = None):
|
||||
return self._raw(url, options=extra_args, with_stats=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ include_directories(
|
|||
# or else they will fail to link. Some of the tests require the special libcurlu
|
||||
# build, so filter those out until we get libcurlu.
|
||||
list(FILTER UNITPROGS EXCLUDE REGEX
|
||||
"unit1394|unit1395|unit1604|unit1608|unit1621|unit1650|unit1653|unit1655|unit1660|unit2600|unit2601|unit2602")
|
||||
"unit1394|unit1395|unit1604|unit1608|unit1621|unit1650|unit1653|unit1655|unit1660|unit2600|unit2601|unit2602|unit2603")
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
foreach(_testfile ${UNITPROGS})
|
||||
add_executable(${_testfile} EXCLUDE_FROM_ALL ${_testfile}.c ${UNITFILES})
|
||||
|
|
|
|||
|
|
@ -158,4 +158,6 @@ unit2601_SOURCES = unit2601.c $(UNITFILES)
|
|||
|
||||
unit2602_SOURCES = unit2602.c $(UNITFILES)
|
||||
|
||||
unit2603_SOURCES = unit2603.c $(UNITFILES)
|
||||
|
||||
unit3200_SOURCES = unit3200.c $(UNITFILES)
|
||||
|
|
|
|||
|
|
@ -38,5 +38,5 @@ UNITPROGS = unit1300 unit1302 unit1303 unit1304 unit1305 unit1307 \
|
|||
unit1620 unit1621 \
|
||||
unit1650 unit1651 unit1652 unit1653 unit1654 unit1655 \
|
||||
unit1660 unit1661 \
|
||||
unit2600 unit2601 unit2602 \
|
||||
unit2600 unit2601 unit2602 unit2603 \
|
||||
unit3200
|
||||
|
|
|
|||
|
|
@ -112,7 +112,6 @@ UNITTEST_START
|
|||
Curl_dyn_init(&dbuf, 32*1024);
|
||||
fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed");
|
||||
if(Curl_dyn_ptr(&dbuf)) {
|
||||
fprintf(stderr, "%s", Curl_dyn_ptr(&dbuf));
|
||||
fail_if(strcmp(Curl_dyn_ptr(&dbuf),
|
||||
"test1: 123\r\ntest1: 123\r\nBla-Bla: thingies\r\n"),
|
||||
"h1 format differs");
|
||||
|
|
@ -121,5 +120,29 @@ UNITTEST_START
|
|||
}
|
||||
|
||||
Curl_dynhds_free(&hds);
|
||||
Curl_dynhds_init(&hds, 128, 4*1024);
|
||||
/* continuation without previous header fails */
|
||||
result = Curl_dynhds_h1_cadd_line(&hds, " indented value");
|
||||
fail_unless(result, "add should have failed");
|
||||
|
||||
/* continuation with previous header must succeed */
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti1: val1"), "add");
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, " val2"), "add indent");
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti2: val1"), "add");
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, "\tval2"), "add indent");
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti3: val1"), "add");
|
||||
fail_if(Curl_dynhds_h1_cadd_line(&hds, " val2"), "add indent");
|
||||
|
||||
Curl_dyn_init(&dbuf, 32*1024);
|
||||
fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed");
|
||||
if(Curl_dyn_ptr(&dbuf)) {
|
||||
fprintf(stderr, "indent concat: %s\n", Curl_dyn_ptr(&dbuf));
|
||||
fail_if(strcmp(Curl_dyn_ptr(&dbuf),
|
||||
"ti1: val1 val2\r\nti2: val1 val2\r\nti3: val1 val2\r\n"),
|
||||
"wrong format");
|
||||
}
|
||||
Curl_dyn_free(&dbuf);
|
||||
|
||||
Curl_dynhds_free(&hds);
|
||||
|
||||
UNITTEST_STOP
|
||||
|
|
|
|||
190
tests/unit/unit2603.c
Normal file
190
tests/unit/unit2603.c
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) 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.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.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "curlcheck.h"
|
||||
|
||||
#include "urldata.h"
|
||||
#include "http.h"
|
||||
#include "http1.h"
|
||||
#include "curl_log.h"
|
||||
|
||||
static CURLcode unit_setup(void)
|
||||
{
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
static void unit_stop(void)
|
||||
{
|
||||
}
|
||||
|
||||
struct tcase {
|
||||
const char **input;
|
||||
const char *default_scheme;
|
||||
const char *method;
|
||||
const char *scheme;
|
||||
const char *authority;
|
||||
const char *path;
|
||||
size_t header_count;
|
||||
size_t input_remain;
|
||||
};
|
||||
|
||||
static void check_eq(const char *s, const char *exp_s, const char *name)
|
||||
{
|
||||
if(s && exp_s) {
|
||||
if(strcmp(s, exp_s)) {
|
||||
fprintf(stderr, "expected %s: '%s' but got '%s'\n", name, exp_s, s);
|
||||
fail("unexpected req component");
|
||||
}
|
||||
}
|
||||
else if(!s && exp_s) {
|
||||
fprintf(stderr, "expected %s: '%s' but got NULL\n", name, exp_s);
|
||||
fail("unexpected req component");
|
||||
}
|
||||
else if(s && !exp_s) {
|
||||
fprintf(stderr, "expected %s: NULL but got '%s'\n", name, s);
|
||||
fail("unexpected req component");
|
||||
}
|
||||
}
|
||||
|
||||
static void parse_success(struct tcase *t)
|
||||
{
|
||||
struct h1_req_parser p;
|
||||
const char *buf;
|
||||
size_t buflen, i, in_len, in_consumed;
|
||||
CURLcode err;
|
||||
ssize_t nread;
|
||||
|
||||
Curl_h1_req_parse_init(&p, 1024);
|
||||
in_len = in_consumed = 0;
|
||||
for(i = 0; t->input[i]; ++i) {
|
||||
buf = t->input[i];
|
||||
buflen = strlen(buf);
|
||||
in_len += buflen;
|
||||
nread = Curl_h1_req_parse_read(&p, buf, buflen, t->default_scheme,
|
||||
0, &err);
|
||||
if(nread < 0) {
|
||||
fprintf(stderr, "got err %d parsing: '%s'\n", err, buf);
|
||||
fail("error consuming");
|
||||
}
|
||||
in_consumed += (size_t)nread;
|
||||
if((size_t)nread != buflen) {
|
||||
if(!p.done) {
|
||||
fprintf(stderr, "only %zd/%zu consumed for: '%s'\n",
|
||||
nread, buflen, buf);
|
||||
fail("not all consumed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fail_if(!p.done, "end not detected");
|
||||
fail_if(!p.req, "not request created");
|
||||
if(t->input_remain != (in_len - in_consumed)) {
|
||||
fprintf(stderr, "expected %zu input bytes to remain, but got %zu\n",
|
||||
t->input_remain, in_len - in_consumed);
|
||||
fail("unexpected input consumption");
|
||||
}
|
||||
if(p.req) {
|
||||
check_eq(p.req->method, t->method, "method");
|
||||
check_eq(p.req->scheme, t->scheme, "scheme");
|
||||
check_eq(p.req->authority, t->authority, "authority");
|
||||
check_eq(p.req->path, t->path, "path");
|
||||
if(Curl_dynhds_count(&p.req->headers) != t->header_count) {
|
||||
fprintf(stderr, "expected %zu headers but got %zu\n", t->header_count,
|
||||
Curl_dynhds_count(&p.req->headers));
|
||||
fail("unexpected req header count");
|
||||
}
|
||||
}
|
||||
|
||||
Curl_h1_req_parse_free(&p);
|
||||
}
|
||||
|
||||
static const char *T1_INPUT[] = {
|
||||
"GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST1a = {
|
||||
T1_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 0
|
||||
};
|
||||
static struct tcase TEST1b = {
|
||||
T1_INPUT, "https", "GET", "https", NULL, "/path", 1, 0
|
||||
};
|
||||
|
||||
static const char *T2_INPUT[] = {
|
||||
"GET /path HTT",
|
||||
"P/1.1\r\nHost: te",
|
||||
"st.curl.se\r\n\r",
|
||||
"\n12345678",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST2 = {
|
||||
T2_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 8
|
||||
};
|
||||
|
||||
static const char *T3_INPUT[] = {
|
||||
"GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
|
||||
"\nUser-Agent: xxx\r\n\r\n",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST3a = {
|
||||
T3_INPUT, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
|
||||
};
|
||||
|
||||
static const char *T4_INPUT[] = {
|
||||
"CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
|
||||
"User-Agent: xxx\r\n",
|
||||
"nothing: \r\n\r\n\n\n",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST4a = {
|
||||
T4_INPUT, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
|
||||
};
|
||||
|
||||
static const char *T5_INPUT[] = {
|
||||
"OPTIONS * HTTP/1.1\r\nContent-Length: 0\r\nBlabla: xxx.yyy\r",
|
||||
"\n\tzzzzzz\r\n\r\n",
|
||||
"123",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST5a = {
|
||||
T5_INPUT, NULL, "OPTIONS", NULL, NULL, "*", 2, 3
|
||||
};
|
||||
|
||||
static const char *T6_INPUT[] = {
|
||||
"PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
|
||||
NULL,
|
||||
};
|
||||
static struct tcase TEST6a = {
|
||||
T6_INPUT, NULL, "PUT", NULL, NULL, "/path", 1, 3
|
||||
};
|
||||
|
||||
UNITTEST_START
|
||||
|
||||
parse_success(&TEST1a);
|
||||
parse_success(&TEST1b);
|
||||
parse_success(&TEST2);
|
||||
parse_success(&TEST3a);
|
||||
parse_success(&TEST4a);
|
||||
parse_success(&TEST5a);
|
||||
parse_success(&TEST6a);
|
||||
|
||||
UNITTEST_STOP
|
||||
Loading…
Add table
Add a link
Reference in a new issue