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#
25import logging
26import re
28import pytest
29from testenv import CurlClient, Env
31log = logging.getLogger(__name__)
34class TestBasic:
36 # simple http: GET
37 def test_01_01_http_get(self, env: Env, httpd):
38 curl = CurlClient(env=env)
39 url = f'http://{env.domain1}:{env.http_port}/data.json'
40 r = curl.http_get(url=url)
41 r.check_response(http_status=200)
42 assert r.json['server'] == env.domain1
44 # simple https: GET, any http version
45 @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
46 def test_01_02_https_get(self, env: Env, httpd):
47 curl = CurlClient(env=env)
48 url = f'https://{env.domain1}:{env.https_port}/data.json'
49 r = curl.http_get(url=url)
50 r.check_response(http_status=200)
51 assert r.json['server'] == env.domain1
53 # simple https: GET, h2 wanted and got
54 @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
55 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
56 def test_01_03_h2_get(self, env: Env, httpd):
57 curl = CurlClient(env=env)
58 url = f'https://{env.domain1}:{env.https_port}/data.json'
59 r = curl.http_get(url=url, extra_args=['--http2'])
60 r.check_response(http_status=200, protocol='HTTP/2')
61 assert r.json['server'] == env.domain1
63 # simple https: GET, h2 unsupported, fallback to h1
64 @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
65 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
66 def test_01_04_h2_unsupported(self, env: Env, httpd):
67 curl = CurlClient(env=env)
68 url = f'https://{env.domain2}:{env.https_port}/data.json'
69 r = curl.http_get(url=url, extra_args=['--http2'])
70 r.check_response(http_status=200, protocol='HTTP/1.1')
71 assert r.json['server'] == env.domain2
73 # simple h3: GET, want h3 and get it
74 @pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
75 def test_01_05_h3_get(self, env: Env, httpd, nghttpx):
76 curl = CurlClient(env=env)
77 url = f'https://{env.domain1}:{env.h3_port}/data.json'
78 r = curl.http_get(url=url, extra_args=['--http3-only'])
79 r.check_response(http_status=200, protocol='HTTP/3')
80 assert r.json['server'] == env.domain1
82 # simple download, check connect/handshake timings
83 @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
84 @pytest.mark.parametrize("proto", Env.http_protos())
85 def test_01_06_timings(self, env: Env, httpd, nghttpx, proto):
86 curl = CurlClient(env=env)
87 url = f'https://{env.authority_for(env.domain1, proto)}/data.json'
88 r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True)
89 r.check_stats(http_status=200, count=1,
90 remote_port=env.port_for(alpn_proto=proto),
91 remote_ip='127.0.0.1')
92 # there are cases where time_connect is reported as 0
93 assert r.stats[0]['time_connect'] >= 0, f'{r.stats[0]}'
94 assert r.stats[0]['time_appconnect'] > 0, f'{r.stats[0]}'
95 # ports are reported correctly
96 assert r.stats[0]['remote_port'] == env.port_for(proto), f'{r.dump_logs()}'
97 assert r.stats[0]['local_port'] > 0, f'{r.dump_logs()}'
99 # simple https: HEAD
100 @pytest.mark.parametrize("proto", Env.http_protos())
101 @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
102 def test_01_07_head(self, env: Env, httpd, nghttpx, proto):
103 curl = CurlClient(env=env)
104 url = f'https://{env.authority_for(env.domain1, proto)}/data.json'
105 r = curl.http_download(urls=[url], with_stats=True, with_headers=True,
106 extra_args=['-I'])
107 r.check_stats(http_status=200, count=1, exitcode=0,
108 remote_port=env.port_for(alpn_proto=proto),
109 remote_ip='127.0.0.1')
110 # got the Content-Length: header, but did not download anything
111 assert r.responses[0]['header']['content-length'] == '30', f'{r.responses[0]}'
112 assert r.stats[0]['size_download'] == 0, f'{r.stats[0]}'
114 # http: GET for HTTP/2, see Upgrade:, 101 switch
115 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
116 def test_01_08_h2_upgrade(self, env: Env, httpd):
117 curl = CurlClient(env=env)
118 url = f'http://{env.domain1}:{env.http_port}/data.json'
119 r = curl.http_get(url=url, extra_args=['--http2'])
120 r.check_exit_code(0)
121 assert len(r.responses) == 2, f'{r.responses}'
122 assert r.responses[0]['status'] == 101, f'{r.responses[0]}'
123 assert r.responses[1]['status'] == 200, f'{r.responses[1]}'
124 assert r.responses[1]['protocol'] == 'HTTP/2', f'{r.responses[1]}'
125 assert r.json['server'] == env.domain1
127 # http: GET for HTTP/2 with prior knowledge
128 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
129 def test_01_09_h2_prior_knowledge(self, env: Env, httpd):
130 curl = CurlClient(env=env)
131 url = f'http://{env.domain1}:{env.http_port}/data.json'
132 r = curl.http_get(url=url, extra_args=['--http2-prior-knowledge'])
133 r.check_exit_code(0)
134 assert len(r.responses) == 1, f'{r.responses}'
135 assert r.response['status'] == 200, f'{r.response}'
136 assert r.response['protocol'] == 'HTTP/2', f'{r.response}'
137 assert r.json['server'] == env.domain1
139 # http: strip TE header in HTTP/2 requests
140 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
141 def test_01_10_te_strip(self, env: Env, httpd):
142 curl = CurlClient(env=env)
143 url = f'https://{env.authority_for(env.domain1, "h2")}/data.json'
144 r = curl.http_get(url=url, extra_args=['--http2', '-H', 'TE: gzip'])
145 r.check_exit_code(0)
146 assert len(r.responses) == 1, f'{r.responses}'
147 assert r.responses[0]['status'] == 200, f'{r.responses[1]}'
148 assert r.responses[0]['protocol'] == 'HTTP/2', f'{r.responses[1]}'
150 # http: large response headers
151 # send 48KB+ sized response headers to check we handle that correctly
152 # larger than 64KB headers expose a bug in Apache HTTP/2 that is not
153 # RSTing the stream correctly when its internal limits are exceeded.
154 @pytest.mark.parametrize("proto", Env.http_protos())
155 def test_01_11_large_resp_headers(self, env: Env, httpd, proto):
156 curl = CurlClient(env=env)
157 url = f'https://{env.authority_for(env.domain1, proto)}' \
158 f'/curltest/tweak?x-hd={48 * 1024}'
159 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[])
160 r.check_exit_code(0)
161 assert len(r.responses) == 1, f'{r.responses}'
162 assert r.responses[0]['status'] == 200, f'{r.responses}'
164 # http: response headers larger than what curl buffers for
165 @pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
166 reason='httpd must be at least 2.4.64')
167 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
168 def test_01_12_xlarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
169 httpd.set_extra_config('base', [
170 f'H2MaxHeaderBlockLen {130 * 1024}',
171 ])
172 httpd.reload_if_config_changed()
173 curl = CurlClient(env=env)
174 url = f'https://{env.authority_for(env.domain1, proto)}' \
175 f'/curltest/tweak?x-hd={128 * 1024}'
176 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[])
177 r.check_exit_code(0)
178 assert len(r.responses) == 1, f'{r.responses}'
179 assert r.responses[0]['status'] == 200, f'{r.responses}'
181 # http: 1 response header larger than what curl buffers for
182 @pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
183 reason='httpd must be at least 2.4.64')
184 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
185 def test_01_13_megalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
186 httpd.set_extra_config('base', [
187 'LogLevel http2:trace2',
188 f'H2MaxHeaderBlockLen {130 * 1024}',
189 ])
190 httpd.reload_if_config_changed()
191 curl = CurlClient(env=env)
192 url = f'https://{env.authority_for(env.domain1, proto)}' \
193 f'/curltest/tweak?x-hd1={128 * 1024}'
194 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[])
195 if proto == 'h2':
196 r.check_exit_code(16) # CURLE_HTTP2
197 else:
198 r.check_exit_code(100) # CURLE_TOO_LARGE
200 # http: several response headers, together > 256 KB
201 # nghttp2 error -905: Too many CONTINUATION frames following a HEADER frame
202 @pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
203 reason='httpd must be at least 2.4.64')
204 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
205 def test_01_14_gigalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
206 httpd.set_extra_config('base', [
207 'LogLevel http2:trace2',
208 f'H2MaxHeaderBlockLen {1024 * 1024}',
209 ])
210 httpd.reload_if_config_changed()
211 curl = CurlClient(env=env)
212 url = f'https://{env.authority_for(env.domain1, proto)}' \
213 f'/curltest/tweak?x-hd={256 * 1024}'
214 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[])
215 if proto == 'h2':
216 r.check_exit_code(56) # CURLE_RECV_ERROR
217 else:
218 r.check_exit_code(0) # 1.1 can do
220 # http: one response header > 256 KB
221 @pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
222 reason='httpd must be at least 2.4.64')
223 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
224 def test_01_15_gigalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
225 httpd.set_extra_config('base', [
226 'LogLevel http2:trace2',
227 f'H2MaxHeaderBlockLen {1024 * 1024}',
228 ])
229 httpd.reload_if_config_changed()
230 curl = CurlClient(env=env)
231 url = f'https://{env.authority_for(env.domain1, proto)}' \
232 f'/curltest/tweak?x-hd1={256 * 1024}'
233 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[])
234 if proto == 'h2':
235 r.check_exit_code(16) # CURLE_HTTP2
236 else:
237 r.check_exit_code(100) # CURLE_TOO_LARGE
239 # http: invalid request headers, GET, issue #16998
240 @pytest.mark.parametrize("proto", Env.http_protos())
241 def test_01_16_inv_req_get(self, env: Env, httpd, nghttpx, proto):
242 curl = CurlClient(env=env)
243 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo'
244 r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
245 '-H', "a: a\x0ab"
246 ])
247 # on h1, request is sent, h2/h3 reject
248 if proto == 'http/1.1':
249 r.check_exit_code(0)
250 else:
251 r.check_exit_code(43)
253 # http: special handling of TE request header
254 @pytest.mark.parametrize("te_in, te_out", [
255 pytest.param('trailers', 'trailers', id='trailers'),
256 pytest.param('chunked', None, id='chunked'),
257 pytest.param('gzip, trailers', 'trailers', id='gzip+trailers'),
258 pytest.param('gzip ;q=0.2;x="y,x", trailers', 'trailers', id='gzip+q+x+trailers'),
259 pytest.param('gzip ;x="trailers", chunks', None, id='gzip+x+chunks'),
260 ])
261 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
262 def test_01_17_TE(self, env: Env, httpd, te_in, te_out):
263 proto = 'h2'
264 curl = CurlClient(env=env)
265 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo'
266 r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
267 with_headers=True,
268 extra_args=['-H', f'TE: {te_in}'])
269 r.check_response(200)
270 if te_out is not None:
271 assert r.responses[0]['header']['request-te'] == te_out, f'{r.responses[0]}'
272 else:
273 assert 'request-te' not in r.responses[0]['header'], f'{r.responses[0]}'
275 # check that an existing https: connection is not reused for http:
276 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
277 def test_01_18_tls_reuse(self, env: Env, httpd):
278 proto = 'h2'
279 curl = CurlClient(env=env)
280 url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json'
281 url2 = f'http://{env.authority_for(env.domain1, proto)}/data.json'
282 r = curl.http_download(urls=[url1, url2], alpn_proto=proto, with_stats=True)
283 assert len(r.stats) == 2
284 assert r.total_connects == 2, f'{r.dump_logs()}'
286 # check that an existing http: connection is not reused for https:
287 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
288 def test_01_19_plain_reuse(self, env: Env, httpd):
289 proto = 'h2'
290 curl = CurlClient(env=env)
291 url1 = f'http://{env.domain1}:{env.http_port}/data.json'
292 url2 = f'https://{env.domain1}:{env.http_port}/data.json'
293 r = curl.http_download(urls=[url1, url2], alpn_proto=proto, with_stats=True)
294 assert len(r.stats) == 2
295 assert r.total_connects == 2, f'{r.dump_logs()}'
297 # use a custom method containing a space
298 # check that h2/h3 did send that in the :method pseudo header. #19543
299 @pytest.mark.skipif(condition=not Env.curl_is_verbose(), reason="needs verbosecurl")
300 @pytest.mark.parametrize("proto", Env.http_protos())
301 def test_01_20_method_space(self, env: Env, proto, httpd):
302 curl = CurlClient(env=env)
303 method = 'IN SANE'
304 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo'
305 r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
306 extra_args=['-X', method])
307 if proto == 'h2' or proto == 'h3':
308 # h2+3 may close the connection for such invalid requests
309 re_m = re.compile(r'.*\[:method: ([^\]]+)\].*')
310 lines = [line for line in r.trace_lines if re_m.match(line)]
311 assert len(lines) == 1, f'{r.dump_logs()}'
312 m = re_m.match(lines[0])
313 assert m.group(1) == method, f'{r.dump_logs()}'
314 else:
315 # h1 should give us a real response
316 assert len(r.stats) == 1
317 r.check_response(http_status=400)
Diagnostics4 git calls · 61 ms
CallStatusSizeTime061 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=55 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 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
fetch2003.2 KiB · hit55 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3324 git.response.cache=HIT git.response.duration_ms=55 git.fetch.wants=e89c1025d6df0018c6b259a9d12a0b1ba86c2f39 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=3324 git.pkt.payload.max=3303 git.sideband.band1.bytes=3302 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
- a5e2093c1db0c69c
- Request
- 2238e7ef…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format