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 difflib
26import filecmp
27import logging
28import os
29import re
30import string
31import sys
32from typing import List, Union
34import pytest
35from testenv import CurlClient, Env, ExecResult, LocalClient
37log = logging.getLogger(__name__)
40class TestUpload:
42 @pytest.fixture(autouse=True, scope='class')
43 @classmethod
44 def _class_scope(cls, env, httpd, nghttpx):
45 env.make_data_file(indir=env.gen_dir, fname="data-10k", fsize=10 * 1024)
46 env.make_data_file(indir=env.gen_dir, fname="data-63k", fsize=63 * 1024)
47 env.make_data_file(indir=env.gen_dir, fname="data-64k", fsize=64 * 1024)
48 env.make_data_file(indir=env.gen_dir, fname="data-100k", fsize=100 * 1024)
49 env.make_data_file(indir=env.gen_dir, fname="data-1m+", fsize=(1024 * 1024) + 1)
50 env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10 * 1024 * 1024)
52 # upload small data, check that this is what was echoed
53 @pytest.mark.parametrize("proto", Env.http_protos())
54 def test_07_01_upload_1_small(self, env: Env, httpd, nghttpx, proto):
55 data = string.digits
56 curl = CurlClient(env=env)
57 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
58 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto)
59 r.check_stats(count=1, http_status=200, exitcode=0)
60 with open(curl.response_file(0)) as fr:
61 respdata = fr.readlines()
62 assert respdata == [data]
64 # upload large data, check that this is what was echoed
65 @pytest.mark.parametrize("proto", Env.http_protos())
66 def test_07_02_upload_1_large(self, env: Env, httpd, nghttpx, proto):
67 fdata = os.path.join(env.gen_dir, 'data-100k')
68 curl = CurlClient(env=env)
69 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
70 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto)
71 r.check_stats(count=1, http_status=200, exitcode=0)
72 with open(fdata) as fi, open(curl.response_file(0)) as fr:
73 indata = fi.readlines()
74 respdata = fr.readlines()
75 assert respdata == indata
77 # upload data sequentially, check that they were echoed
78 @pytest.mark.parametrize("proto", Env.http_protos())
79 def test_07_10_upload_sequential(self, env: Env, httpd, nghttpx, proto):
80 count = 20
81 data = string.digits
82 curl = CurlClient(env=env)
83 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
84 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto)
85 r.check_stats(count=count, http_status=200, exitcode=0)
86 for i in range(count):
87 with open(curl.response_file(i)) as fr:
88 respdata = fr.readlines()
89 assert respdata == [data]
91 # upload data parallel, check that they were echoed
92 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
93 def test_07_11_upload_parallel(self, env: Env, httpd, nghttpx, proto):
94 # limit since we use a separate connection in h1
95 count = 20
96 data = string.digits
97 curl = CurlClient(env=env)
98 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
99 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
100 extra_args=['--parallel'])
101 r.check_stats(count=count, http_status=200, exitcode=0)
102 for i in range(count):
103 with open(curl.response_file(i)) as fr:
104 respdata = fr.readlines()
105 assert respdata == [data]
107 # upload large data sequentially, check that this is what was echoed
108 @pytest.mark.parametrize("proto", Env.http_protos())
109 def test_07_12_upload_seq_large(self, env: Env, httpd, nghttpx, proto):
110 fdata = os.path.join(env.gen_dir, 'data-100k')
111 count = 10
112 curl = CurlClient(env=env)
113 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
114 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto)
115 r.check_response(count=count, http_status=200)
116 with open(fdata) as fi:
117 indata = fi.readlines()
118 r.check_stats(count=count, http_status=200, exitcode=0)
119 for i in range(count):
120 with open(curl.response_file(i)) as fr:
121 respdata = fr.readlines()
122 assert respdata == indata
124 # upload very large data sequentially, check that this is what was echoed
125 @pytest.mark.parametrize("proto", Env.http_protos())
126 def test_07_13_upload_seq_large(self, env: Env, httpd, nghttpx, proto):
127 fdata = os.path.join(env.gen_dir, 'data-10m')
128 count = 2
129 curl = CurlClient(env=env)
130 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
131 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto)
132 r.check_stats(count=count, http_status=200, exitcode=0)
133 with open(fdata) as fi:
134 indata = fi.readlines()
135 for i in range(count):
136 with open(curl.response_file(i)) as fr:
137 respdata = fr.readlines()
138 assert respdata == indata
140 # upload from stdin, issue #14870
141 @pytest.mark.parametrize("proto", Env.http_protos())
142 @pytest.mark.parametrize("indata", [
143 '', '1', '123\n456andsomething\n\n'
144 ])
145 def test_07_14_upload_stdin(self, env: Env, httpd, nghttpx, proto, indata):
146 count = 1
147 curl = CurlClient(env=env)
148 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-{count-1}]'
149 r = curl.http_put(urls=[url], data=indata, alpn_proto=proto)
150 r.check_stats(count=count, http_status=200, exitcode=0)
151 for i in range(count):
152 with open(curl.response_file(i)) as fr:
153 respdata = fr.readlines()
154 assert respdata == [f'{len(indata)}']
156 @pytest.mark.parametrize("proto", Env.http_protos())
157 def test_07_15_hx_put(self, env: Env, httpd, nghttpx, proto):
158 count = 2
159 upload_size = 128 * 1024
160 url = f'https://localhost:{env.https_port}/curltest/put'
161 client = LocalClient(name='cli_hx_upload', env=env)
162 if not client.exists():
163 pytest.skip(f'example client not built: {client.name}')
164 r = client.run(args=[
165 '-n', f'{count}', '-S', f'{upload_size}', '-V', proto, url
166 ])
167 r.check_exit_code(0)
168 self.check_downloads(client, r, [f"{upload_size}"], count)
170 @pytest.mark.parametrize("proto", Env.http_protos())
171 def test_07_16_hx_put_reuse(self, env: Env, httpd, nghttpx, proto):
172 count = 2
173 upload_size = 128 * 1024
174 url = f'https://localhost:{env.https_port}/curltest/put'
175 client = LocalClient(name='cli_hx_upload', env=env)
176 if not client.exists():
177 pytest.skip(f'example client not built: {client.name}')
178 r = client.run(args=[
179 '-n', f'{count}', '-S', f'{upload_size}', '-R', '-V', proto, url
180 ])
181 r.check_exit_code(0)
182 self.check_downloads(client, r, [f"{upload_size}"], count)
184 @pytest.mark.parametrize("proto", Env.http_protos())
185 def test_07_17_hx_post_reuse(self, env: Env, httpd, nghttpx, proto):
186 count = 2
187 upload_size = 128 * 1024
188 url = f'https://localhost:{env.https_port}/curltest/echo'
189 client = LocalClient(name='cli_hx_upload', env=env)
190 if not client.exists():
191 pytest.skip(f'example client not built: {client.name}')
192 r = client.run(args=[
193 '-n', f'{count}', '-M', 'POST', '-S', f'{upload_size}', '-R', '-V', proto, url
194 ])
195 r.check_exit_code(0)
196 self.check_downloads(client, r, ["x" * upload_size], count)
198 # upload data parallel, check that they were echoed
199 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
200 def test_07_20_upload_parallel(self, env: Env, httpd, nghttpx, proto):
201 # limit since we use a separate connection in h1
202 count = 10
203 data = string.digits
204 curl = CurlClient(env=env)
205 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
206 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
207 extra_args=['--parallel'])
208 r.check_stats(count=count, http_status=200, exitcode=0)
209 for i in range(count):
210 with open(curl.response_file(i)) as fr:
211 respdata = fr.readlines()
212 assert respdata == [data]
214 # upload large data parallel, check that this is what was echoed
215 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
216 def test_07_21_upload_parallel_large(self, env: Env, httpd, nghttpx, proto):
217 fdata = os.path.join(env.gen_dir, 'data-100k')
218 # limit since we use a separate connection in h1
219 count = 10
220 curl = CurlClient(env=env)
221 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-{count-1}]'
222 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto,
223 extra_args=['--parallel'])
224 r.check_response(count=count, http_status=200)
225 self.check_download(r, count, fdata, curl)
227 # upload single large data to a URL that fails uploads, causing RESETs
228 # We used to test h3 as well, but this is unreliable in CI with nghttpx
229 # not reporting a RESET sometimes.
230 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
231 def test_07_22_upload_fail(self, env: Env, httpd, nghttpx, proto):
232 fdata = os.path.join(env.gen_dir, 'data-10m')
233 count = 1
234 curl = CurlClient(env=env)
235 url = f'https://{env.authority_for(env.domain1, proto)}'\
236 f'/curltest/tweak?status=200&delay=5ms&chunks=1&body_error=reset&id=[0-{count-1}]'
237 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto,
238 extra_args=['--parallel'])
239 # depending on timing and protocol, we might get CURLE_PARTIAL_FILE or
240 # CURLE_SEND_ERROR or CURLE_HTTP3 or CURLE_HTTP2_STREAM
241 r.check_stats(count=count, exitcode=[18, 55, 56, 92, 95])
243 # PUT 100k
244 @pytest.mark.parametrize("proto", Env.http_protos())
245 def test_07_30_put_100k(self, env: Env, httpd, nghttpx, proto):
246 fdata = os.path.join(env.gen_dir, 'data-100k')
247 count = 1
248 curl = CurlClient(env=env)
249 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-{count-1}]'
250 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto,
251 extra_args=['--parallel'])
252 r.check_stats(count=count, http_status=200, exitcode=0)
253 exp_data = [f'{os.path.getsize(fdata)}']
254 r.check_response(count=count, http_status=200)
255 for i in range(count):
256 with open(curl.response_file(i)) as fr:
257 respdata = fr.readlines()
258 assert respdata == exp_data
260 # PUT 10m
261 @pytest.mark.parametrize("proto", Env.http_protos())
262 def test_07_31_put_10m(self, env: Env, httpd, nghttpx, proto):
263 fdata = os.path.join(env.gen_dir, 'data-10m')
264 count = 1
265 curl = CurlClient(env=env)
266 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-{count-1}]&chunk_delay=2ms'
267 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto,
268 extra_args=['--parallel'])
269 r.check_stats(count=count, http_status=200, exitcode=0)
270 exp_data = [f'{os.path.getsize(fdata)}']
271 r.check_response(count=count, http_status=200)
272 for i in range(count):
273 with open(curl.response_file(i)) as fr:
274 respdata = fr.readlines()
275 assert respdata == exp_data
277 # issue #10591
278 @pytest.mark.parametrize("proto", Env.http_protos())
279 def test_07_32_issue_10591(self, env: Env, httpd, nghttpx, proto):
280 fdata = os.path.join(env.gen_dir, 'data-10m')
281 count = 1
282 curl = CurlClient(env=env)
283 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-{count-1}]'
284 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto)
285 r.check_stats(count=count, http_status=200, exitcode=0)
287 # issue #11157, upload that is 404'ed by server, needs to terminate
288 # correctly and not time out on sending
289 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
290 def test_07_33_issue_11157a(self, env: Env, httpd, nghttpx):
291 proto = 'h2'
292 fdata = os.path.join(env.gen_dir, 'data-10m')
293 # send a POST to our PUT handler which will send immediately a 404 back
294 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put'
295 curl = CurlClient(env=env)
296 r = curl.run_direct(with_stats=True, args=[
297 '--resolve', f'{env.authority_for(env.domain1, proto)}:127.0.0.1',
298 '--cacert', env.ca.cert_file,
299 '--request', 'POST',
300 '--max-time', '5', '-v',
301 '--url', url,
302 '--form', 'idList=12345678',
303 '--form', 'pos=top',
304 '--form', 'name=mr_test',
305 '--form', f'fileSource=@{fdata};type=application/pdf',
306 ])
307 assert r.exit_code == 0, f'{r}'
308 r.check_stats(1, 404)
310 # issue #11157, send upload that is slowly read in
311 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
312 def test_07_33_issue_11157b(self, env: Env, httpd, nghttpx):
313 proto = 'h2'
314 fdata = os.path.join(env.gen_dir, 'data-10m')
315 # tell our test PUT handler to read the upload more slowly, so
316 # that the send buffering and transfer loop needs to wait
317 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?chunk_delay=2ms'
318 curl = CurlClient(env=env)
319 r = curl.run_direct(with_stats=True, args=[
320 '--verbose', '--trace-config', 'ids,time',
321 '--resolve', f'{env.authority_for(env.domain1, proto)}:127.0.0.1',
322 '--cacert', env.ca.cert_file,
323 '--request', 'PUT',
324 '--max-time', '10', '-v',
325 '--url', url,
326 '--form', 'idList=12345678',
327 '--form', 'pos=top',
328 '--form', 'name=mr_test',
329 '--form', f'fileSource=@{fdata};type=application/pdf',
330 ])
331 assert r.exit_code == 0, r.dump_logs()
332 r.check_stats(1, 200)
334 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
335 def test_07_34_issue_11194(self, env: Env, httpd, nghttpx):
336 proto = 'h2'
337 # tell our test PUT handler to read the upload more slowly, so
338 # that the send buffering and transfer loop needs to wait
339 fdata = os.path.join(env.gen_dir, 'data-100k')
340 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put'
341 curl = CurlClient(env=env)
342 r = curl.run_direct(with_stats=True, args=[
343 '--verbose', '--trace-config', 'ids,time',
344 '--resolve', f'{env.authority_for(env.domain1, proto)}:127.0.0.1',
345 '--cacert', env.ca.cert_file,
346 '--request', 'PUT',
347 '--digest', '--user', 'test:test',
348 '--data-binary', f'@{fdata}',
349 '--url', url,
350 ])
351 assert r.exit_code == 0, r.dump_logs()
352 r.check_stats(1, 200)
354 # upload large data on a h1 to h2 upgrade
355 @pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
356 def test_07_35_h1_h2_upgrade_upload(self, env: Env, httpd, nghttpx):
357 fdata = os.path.join(env.gen_dir, 'data-100k')
358 curl = CurlClient(env=env)
359 url = f'http://{env.domain1}:{env.http_port}/curltest/echo?id=[0-0]'
360 r = curl.http_upload(urls=[url], data=f'@{fdata}', extra_args=[
361 '--http2'
362 ])
363 r.check_response(count=1, http_status=200)
364 # apache does not Upgrade on request with a body
365 assert r.stats[0]['http_version'] == '1.1', f'{r}'
366 with open(fdata) as fi, open(curl.response_file(0)) as fr:
367 indata = fi.readlines()
368 respdata = fr.readlines()
369 assert respdata == indata
371 # upload to a 301,302,303 response
372 @pytest.mark.parametrize("redir", ['301', '302', '303'])
373 @pytest.mark.parametrize("proto", Env.http_protos())
374 def test_07_36_upload_30x(self, env: Env, httpd, nghttpx, redir, proto):
375 if proto == 'h3' and env.curl_uses_ossl_quic():
376 pytest.skip("OpenSSL's own QUIC is flaky here")
377 data = string.digits * 10
378 curl = CurlClient(env=env)
379 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo{redir}?id=[0-0]'
380 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
381 '-L', '--trace-config', 'http/2,http/3'
382 ])
383 r.check_response(count=1, http_status=200)
384 with open(curl.response_file(0)) as fr:
385 respdata = fr.readlines()
386 assert respdata == [] # was transformed to a GET
388 # upload to a 307 response
389 @pytest.mark.parametrize("proto", Env.http_protos())
390 def test_07_37_upload_307(self, env: Env, httpd, nghttpx, proto):
391 if proto == 'h3' and env.curl_uses_ossl_quic():
392 pytest.skip("OpenSSL's own QUIC is flaky here")
393 data = string.digits * 10
394 curl = CurlClient(env=env)
395 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo307?id=[0-0]'
396 r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
397 '-L', '--trace-config', 'http/2,http/3'
398 ])
399 r.check_response(count=1, http_status=200)
400 with open(curl.response_file(0)) as fr:
401 respdata = fr.readlines()
402 assert respdata == [data] # was POST again
404 # POST form data, yet another code path in transfer
405 @pytest.mark.parametrize("proto", Env.http_protos())
406 def test_07_38_form_small(self, env: Env, httpd, nghttpx, proto):
407 curl = CurlClient(env=env)
408 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
409 r = curl.http_form(urls=[url], alpn_proto=proto, form={
410 'name1': 'value1',
411 })
412 r.check_stats(count=1, http_status=200, exitcode=0)
414 # POST data urlencoded, small enough to be sent with request headers
415 @pytest.mark.parametrize("proto", Env.http_protos())
416 def test_07_39_post_urlenc_small(self, env: Env, httpd, nghttpx, proto):
417 fdata = os.path.join(env.gen_dir, 'data-63k')
418 curl = CurlClient(env=env)
419 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
420 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
421 '--trace-config', 'http/2,http/3'
422 ])
423 r.check_stats(count=1, http_status=200, exitcode=0)
424 with open(fdata) as fi, open(curl.response_file(0)) as fr:
425 indata = fi.readlines()
426 respdata = fr.readlines()
427 assert respdata == indata
429 # POST data urlencoded, large enough to be sent separate from request headers
430 @pytest.mark.parametrize("proto", Env.http_protos())
431 def test_07_40_post_urlenc_large(self, env: Env, httpd, nghttpx, proto):
432 fdata = os.path.join(env.gen_dir, 'data-64k')
433 curl = CurlClient(env=env)
434 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
435 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
436 '--trace-config', 'http/2,http/3'
437 ])
438 r.check_stats(count=1, http_status=200, exitcode=0)
439 with open(fdata) as fi, open(curl.response_file(0)) as fr:
440 indata = fi.readlines()
441 respdata = fr.readlines()
442 assert respdata == indata
444 # POST data urlencoded, small enough to be sent with request headers
445 # and request headers are so large that the first send is larger
446 # than our default upload buffer length (64KB).
447 # Unfixed, this will fail when run with CURL_DBG_SOCK_WBLOCK=80 most
448 # of the time
449 @pytest.mark.parametrize("proto", Env.http_protos())
450 def test_07_41_post_urlenc_small(self, env: Env, httpd, nghttpx, proto):
451 if proto == 'h3' and env.curl_uses_lib('quiche'):
452 pytest.skip("quiche has CWND issues with large requests")
453 fdata = os.path.join(env.gen_dir, 'data-63k')
454 curl = CurlClient(env=env)
455 extra_args = ['--trace-config', 'http/2,http/3']
456 # add enough headers so that the first send chunk is > 64KB
457 for i in range(63):
458 extra_args.extend(['-H', f'x{i:02d}: {"y"*1019}'])
459 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
460 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=extra_args)
461 r.check_stats(count=1, http_status=200, exitcode=0)
462 with open(fdata) as fi, open(curl.response_file(0)) as fr:
463 indata = fi.readlines()
464 respdata = fr.readlines()
465 assert respdata == indata
467 def check_download(self, r: ExecResult, count: int, srcfile: Union[str, os.PathLike], curl: CurlClient):
468 for i in range(count):
469 dfile = curl.download_file(i)
470 assert os.path.exists(dfile), f'download {dfile} missing\n{r.dump_logs()}'
471 if not filecmp.cmp(srcfile, dfile, shallow=False):
472 with open(srcfile) as fa, open(dfile) as fb:
473 a = fa.readlines()
474 b = fb.readlines()
475 diff = "".join(difflib.unified_diff(a=a, b=b,
476 fromfile=srcfile,
477 tofile=dfile,
478 n=1))
479 assert False, f'download {dfile} differs:\n{diff}\n{r.dump_logs()}'
481 # upload data, pause, let connection die with an incomplete response
482 # issues #11769 #13260
483 @pytest.mark.parametrize("proto", Env.http_protos())
484 def test_07_42a_upload_disconnect(self, env: Env, httpd, nghttpx, proto):
485 client = LocalClient(name='cli_upload_pausing', env=env, timeout=60)
486 if not client.exists():
487 pytest.skip(f'example client not built: {client.name}')
488 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]&die_after=0'
489 r = client.run(['-V', proto, url])
490 if r.exit_code == 18: # PARTIAL_FILE is always ok
491 pass
492 elif proto == 'h2':
493 # CURLE_HTTP2, CURLE_HTTP2_STREAM
494 assert r.exit_code in [16, 92], f'unexpected exit code\n{r.dump_logs()}'
495 elif proto == 'h3':
496 r.check_exit_code(95) # CURLE_HTTP3 also ok
497 else:
498 r.check_exit_code(18) # will fail as it should
500 # upload data, pause, let connection die without any response at all
501 @pytest.mark.parametrize("proto", Env.http_protos())
502 def test_07_42b_upload_disconnect(self, env: Env, httpd, nghttpx, proto):
503 client = LocalClient(name='cli_upload_pausing', env=env, timeout=60)
504 if not client.exists():
505 pytest.skip(f'example client not built: {client.name}')
506 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=0&just_die=1'
507 r = client.run(['-V', proto, url])
508 exp_code = 52 # GOT_NOTHING
509 if proto == 'h2' or proto == 'h3':
510 exp_code = 0 # we get a 500 from the server
511 r.check_exit_code(exp_code) # GOT_NOTHING
513 # upload data, pause, let connection die after 100 continue
514 @pytest.mark.parametrize("proto", Env.http_protos())
515 def test_07_42c_upload_disconnect(self, env: Env, httpd, nghttpx, proto):
516 client = LocalClient(name='cli_upload_pausing', env=env, timeout=60)
517 if not client.exists():
518 pytest.skip(f'example client not built: {client.name}')
519 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=0&die_after_100=1'
520 r = client.run(['-V', proto, url])
521 exp_code = 52 # GOT_NOTHING
522 if proto == 'h2' or proto == 'h3':
523 exp_code = 0 # we get a 500 from the server
524 r.check_exit_code(exp_code) # GOT_NOTHING
526 @pytest.mark.parametrize("proto", Env.http_protos())
527 def test_07_43_upload_denied(self, env: Env, httpd, nghttpx, proto):
528 fdata = os.path.join(env.gen_dir, 'data-10m')
529 count = 1
530 max_upload = 128 * 1024
531 curl = CurlClient(env=env)
532 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?'\
533 f'id=[0-{count-1}]&max_upload={max_upload}'
534 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto,
535 extra_args=['--trace-config', 'all'])
536 r.check_stats(count=count, http_status=413, exitcode=0)
538 @pytest.mark.parametrize("proto", Env.http_protos())
539 @pytest.mark.parametrize("httpcode", [301, 302, 307, 308])
540 def test_07_44_put_redir(self, env: Env, httpd, nghttpx, proto, httpcode):
541 count = 1
542 upload_size = 128 * 1024
543 url = f'https://localhost:{env.https_port}/curltest/put-redir-{httpcode}'
544 client = LocalClient(name='cli_hx_upload', env=env)
545 if not client.exists():
546 pytest.skip(f'example client not built: {client.name}')
547 r = client.run(args=[
548 '-n', f'{count}', '-l', '-S', f'{upload_size}', '-V', proto, url
549 ])
550 r.check_exit_code(0)
551 results = [int(m.group(1)) for line in r.trace_lines
552 if (m := re.match(r'.* FINISHED, result=(\d+), response=(\d+)', line))]
553 httpcodes = [int(m.group(2)) for line in r.trace_lines
554 if (m := re.match(r'.* FINISHED, result=(\d+), response=(\d+)', line))]
555 if httpcode == 308:
556 assert results[0] == 65, f'{r}' # could not rewind input
557 else:
558 assert httpcodes[0] == httpcode, f'{r}'
560 # speed limited on put handler
561 @pytest.mark.parametrize("proto", Env.http_protos())
562 def test_07_50_put_speed_limit(self, env: Env, httpd, nghttpx, proto):
563 count = 1
564 fdata = os.path.join(env.gen_dir, 'data-100k')
565 up_len = 100 * 1024
566 speed_limit = 50 * 1024
567 curl = CurlClient(env=env)
568 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-0]'
569 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto,
570 with_headers=True, extra_args=[
571 '--limit-rate', f'{speed_limit}'
572 ])
573 r.check_response(count=count, http_status=200)
574 assert r.responses[0]['header']['received-length'] == f'{up_len}', f'{r.responses[0]}'
575 up_speed = r.stats[0]['speed_upload']
576 assert up_speed <= (speed_limit * 1.1), f'{r.stats[0]}'
578 # speed limited on echo handler
579 @pytest.mark.parametrize("proto", Env.http_protos())
580 def test_07_51_echo_speed_limit(self, env: Env, httpd, nghttpx, proto):
581 count = 1
582 fdata = os.path.join(env.gen_dir, 'data-100k')
583 speed_limit = 50 * 1024
584 curl = CurlClient(env=env)
585 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
586 r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto,
587 with_headers=True, extra_args=[
588 '--limit-rate', f'{speed_limit}'
589 ])
590 r.check_response(count=count, http_status=200)
591 up_speed = r.stats[0]['speed_upload']
592 assert up_speed <= (speed_limit * 1.1), f'{r.stats[0]}'
594 # upload larger data, triggering "Expect: 100-continue" code paths
595 @pytest.mark.parametrize("proto", ['http/1.1'])
596 def test_07_60_upload_exp100(self, env: Env, httpd, nghttpx, proto):
597 fdata = os.path.join(env.gen_dir, 'data-1m+')
598 read_delay = 1
599 curl = CurlClient(env=env)
600 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-0]'\
601 f'&read_delay={read_delay}s'
602 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto, extra_args=[
603 '--expect100-timeout', f'{read_delay+1}'
604 ])
605 r.check_stats(count=1, http_status=200, exitcode=0)
607 # upload larger data, triggering "Expect: 100-continue" code paths
608 @pytest.mark.parametrize("proto", ['http/1.1'])
609 def test_07_61_upload_exp100_timeout(self, env: Env, httpd, nghttpx, proto):
610 fdata = os.path.join(env.gen_dir, 'data-1m+')
611 read_delay = 2
612 curl = CurlClient(env=env)
613 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/put?id=[0-0]'\
614 f'&read_delay={read_delay}s'
615 r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto, extra_args=[
616 '--expect100-timeout', f'{read_delay-1}'
617 ])
618 r.check_stats(count=1, http_status=200, exitcode=0)
620 # issue #15688 when posting a form and cr_mime_read() is called with
621 # length < 4, we did not progress
622 @pytest.mark.parametrize("proto", ['http/1.1'])
623 def test_07_62_upload_issue_15688(self, env: Env, httpd, proto):
624 # this length leads to (including multipart formatting) to a
625 # client reader invocation with length 1.
626 upload_len = 196169
627 fname = f'data-{upload_len}'
628 env.make_data_file(indir=env.gen_dir, fname=fname, fsize=upload_len)
629 fdata = os.path.join(env.gen_dir, fname)
630 curl = CurlClient(env=env)
631 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'
632 r = curl.http_form(urls=[url], form={
633 'file': f'@{fdata}',
634 }, alpn_proto=proto, extra_args=[
635 '--max-time', '10'
636 ])
637 r.check_stats(count=1, http_status=200, exitcode=0)
639 @pytest.mark.parametrize("proto", ['http/1.1'])
640 def test_07_63_upload_exp100_paused(self, env: Env, httpd, nghttpx, proto):
641 read_delay = 1
642 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo?id=[0-0]'\
643 f'&read_delay={read_delay}s'
644 upload_size = 128 * 1024
645 client = LocalClient(name='cli_hx_upload', env=env)
646 if not client.exists():
647 pytest.skip(f'example client not built: {client.name}')
648 r = client.run(args=[
649 '-n', '1',
650 '-S', f'{upload_size}',
651 '-P', '1',
652 '-M', 'MIME',
653 '-r', f'{env.domain1}:{env.port_for(proto)}:127.0.0.1',
654 '-V', proto, url
655 ])
656 r.check_exit_code(0)
658 # nghttpx is the only server we have that supports TLS early data
659 @pytest.mark.skipif(condition=not Env.have_h3_server(), reason="no QUIC in nghttpx")
660 @pytest.mark.parametrize("proto,upload_size", [
661 pytest.param('http/1.1', 100, id='h1-small-body'),
662 pytest.param('http/1.1', 10 * 1024, id='h1-medium-body'),
663 pytest.param('http/1.1', 32 * 1024, id='h1-limited-body'),
664 pytest.param('h2', 10 * 1024, id='h2-medium-body'),
665 pytest.param('h2', 32 * 1024, id='h2-limited-body'),
666 pytest.param('h3', 1024, id='h3-small-body'),
667 pytest.param('h3', 1024 * 1024, id='h3-limited-body'),
668 ])
669 def test_07_70_put_earlydata(self, env: Env, httpd, nghttpx, proto, upload_size):
670 if not env.curl_can_early_data():
671 pytest.skip('TLS earlydata not implemented')
672 if proto == 'h2' and not env.have_h2_curl():
673 pytest.skip("h2 not supported")
674 if proto == 'h3' and \
675 (not env.have_h3() or not env.curl_can_h3_early_data()):
676 pytest.skip("h3 not supported")
677 if proto != 'h3' and sys.platform.startswith('darwin') and env.ci_run:
678 pytest.skip('failing on macOS CI runners')
679 if proto == 'h3' and env.curl_uses_lib('wolfssl'):
680 pytest.skip('h3 wolfssl early data failing')
681 if proto == 'h3' and env.curl_uses_lib('gnutls'):
682 pytest.skip('h3 gnutls early data failing')
683 count = 2
684 # we want this test to always connect to nghttpx, since it is
685 # the only server we have that supports TLS earlydata
686 port = env.port_for(proto)
687 if proto != 'h3':
688 port = env.nghttpx_https_port
689 url = f'https://{env.domain1}:{port}/curltest/put'
690 client = LocalClient(name='cli_hx_upload', env=env)
691 if not client.exists():
692 pytest.skip(f'example client not built: {client.name}')
693 r = client.run(args=[
694 '-n', f'{count}',
695 '-e', # use TLS earlydata
696 '-f', # forbid reuse of connections
697 '-l', # announce upload length, no 'Expect: 100'
698 '-S', f'{upload_size}',
699 '-r', f'{env.domain1}:{port}:127.0.0.1',
700 '-V', proto, url
701 ])
702 r.check_exit_code(0)
703 self.check_downloads(client, r, [f"{upload_size}"], count)
704 earlydata = {}
705 for line in r.trace_lines:
706 m = re.match(r'^\[t-(\d+)] EarlyData: (-?\d+)', line)
707 if m:
708 earlydata[int(m.group(1))] = int(m.group(2))
709 # 1st transfer did not use early data
710 assert earlydata[0] == 0, f'{earlydata}\n{r.dump_logs()}'
711 # depending on cpu load, the amount of early data might differ.
712 # when the server is slow, we might send more. when curl is slow,
713 # we might send less before the server handshakes.
714 assert 0 < earlydata[1] <= (upload_size + 1024), f'{earlydata}\n{r.dump_logs()}'
716 def check_downloads(self, client, r, source: List[str], count: int,
717 complete: bool = True):
718 for i in range(count):
719 dfile = client.download_file(i)
720 assert os.path.exists(dfile), f'download {dfile} missing\n{r.dump_logs()}'
721 if complete:
722 with open(dfile) as fb:
723 b = fb.readlines()
724 diff = "".join(difflib.unified_diff(a=source, b=b,
725 fromfile='-',
726 tofile=dfile,
727 n=1))
728 assert not diff, f'download {dfile} differs:\n{diff}\n{r.dump_logs()}'
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 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 · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=24 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 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
fetch2006.4 KiB · hit24 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=6519 git.response.cache=HIT git.response.duration_ms=24 git.fetch.wants=13da592605303954af5ca6ce41615fae0a117e62 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=6519 git.pkt.payload.max=6498 git.sideband.band1.bytes=6497 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
- a5e2c0b7a96889da
- Request
- bdfab60a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format