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/* This is based on the PoC client of issue #11982
25 */
26#include "first.h"
28#include "testtrace.h"
30static void usage_h2_pausing(const char *msg)
31{
32 if(msg)
33 curl_mfprintf(stderr, "%s\n", msg);
34 curl_mfprintf(stderr,
35 "usage: [options] url\n"
36 " pause downloads with following options:\n"
37 " -V http_version (http/1.1, h2, h3) http version to use\n"
38 );
39}
41struct handle {
42 size_t idx;
43 int paused;
44 int resumed;
45 int errored;
46 int fail_write;
47 CURL *curl;
48};
50static size_t cb(char *data, size_t size, size_t nmemb, void *clientp)
51{
52 size_t realsize = size * nmemb;
53 struct handle *handle = (struct handle *)clientp;
54 curl_off_t totalsize;
56 (void)data;
57 if(curl_easy_getinfo(handle->curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T,
58 &totalsize) == CURLE_OK)
59 curl_mfprintf(stderr, "INFO: [%zu] write, "
60 "Content-Length %" CURL_FORMAT_CURL_OFF_T "\n",
61 handle->idx, totalsize);
63 if(!handle->resumed) {
64 ++handle->paused;
65 curl_mfprintf(stderr, "INFO: [%zu] write, PAUSING %d time on %zu bytes\n",
66 handle->idx, handle->paused, realsize);
67 DEBUGASSERT(handle->paused == 1);
68 return CURL_WRITEFUNC_PAUSE;
69 }
70 if(handle->fail_write) {
71 ++handle->errored;
72 curl_mfprintf(stderr, "INFO: [%zu] FAIL write of %zu bytes, %d time\n",
73 handle->idx, realsize, handle->errored);
74 return CURL_WRITEFUNC_ERROR;
75 }
76 curl_mfprintf(stderr, "INFO: [%zu] write, accepting %zu bytes\n",
77 handle->idx, realsize);
78 return realsize;
79}
81static CURLcode test_cli_h2_pausing(const char *URL)
82{
83 struct handle handles[2];
84 CURLM *multi = NULL;
85 int still_running = 1, msgs_left, numfds;
86 size_t i;
87 CURLMsg *msg;
88 int rounds = 0;
89 CURLcode result = CURLE_OK;
90 CURLU *cu;
91 struct curl_slist *resolve = NULL;
92 char resolve_buf[1024];
93 const char *url;
94 char *host = NULL, *port = NULL;
95 int all_paused = 0;
96 int resume_round = -1;
97 long http_version = CURL_HTTP_VERSION_2_0;
98 int ch;
100 (void)URL;
102 while((ch = cgetopt(test_argc, test_argv, "hV:")) != -1) {
103 switch(ch) {
104 case 'h':
105 usage_h2_pausing(NULL);
106 return (CURLcode)2;
107 case 'V': {
108 if(!strcmp("http/1.1", coptarg))
109 http_version = CURL_HTTP_VERSION_1_1;
110 else if(!strcmp("h2", coptarg))
111 http_version = CURL_HTTP_VERSION_2_0;
112 else if(!strcmp("h3", coptarg))
113 http_version = CURL_HTTP_VERSION_3ONLY;
114 else {
115 usage_h2_pausing("invalid http version");
116 return (CURLcode)1;
117 }
118 break;
119 }
120 default:
121 usage_h2_pausing("invalid option");
122 return (CURLcode)1;
123 }
124 }
125 test_argc -= coptind;
126 test_argv += coptind;
128 if(test_argc != 1) {
129 curl_mfprintf(stderr, "ERROR: need URL as argument\n");
130 return (CURLcode)2;
131 }
132 url = test_argv[0];
134 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
135 curl_mfprintf(stderr, "curl_global_init() failed\n");
136 return (CURLcode)3;
137 }
139 curl_global_trace("ids,time,http/2,http/3");
141 memset(handles, 0, sizeof(handles));
143 cu = curl_url();
144 if(!cu) {
145 curl_mfprintf(stderr, "out of memory\n");
146 result = (CURLcode)1;
147 goto cleanup;
148 }
149 if(curl_url_set(cu, CURLUPART_URL, url, 0)) {
150 curl_mfprintf(stderr, "not a URL: '%s'\n", url);
151 result = (CURLcode)1;
152 goto cleanup;
153 }
154 if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
155 curl_mfprintf(stderr, "could not get host of '%s'\n", url);
156 result = (CURLcode)1;
157 goto cleanup;
158 }
159 if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
160 curl_mfprintf(stderr, "could not get port of '%s'\n", url);
161 result = (CURLcode)1;
162 goto cleanup;
163 }
165 curl_msnprintf(resolve_buf, sizeof(resolve_buf) - 1, "%s:%s:127.0.0.1",
166 host, port);
167 resolve = curl_slist_append(resolve, resolve_buf);
169 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
170 handles[i].idx = i;
171 handles[i].paused = 0;
172 handles[i].resumed = 0;
173 handles[i].errored = 0;
174 handles[i].fail_write = 1;
175 handles[i].curl = curl_easy_init();
176 if(!handles[i].curl ||
177 curl_easy_setopt(handles[i].curl, CURLOPT_WRITEFUNCTION, cb)
178 != CURLE_OK ||
179 curl_easy_setopt(handles[i].curl, CURLOPT_WRITEDATA, &handles[i])
180 != CURLE_OK ||
181 curl_easy_setopt(handles[i].curl, CURLOPT_FOLLOWLOCATION, 1L)
182 != CURLE_OK ||
183 curl_easy_setopt(handles[i].curl, CURLOPT_VERBOSE, 1L) != CURLE_OK ||
184 curl_easy_setopt(handles[i].curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb)
185 != CURLE_OK ||
186 curl_easy_setopt(handles[i].curl, CURLOPT_SSL_VERIFYPEER, 0L)
187 != CURLE_OK ||
188 curl_easy_setopt(handles[i].curl, CURLOPT_RESOLVE, resolve)
189 != CURLE_OK ||
190 curl_easy_setopt(handles[i].curl, CURLOPT_PIPEWAIT, 1L) != CURLE_OK ||
191 curl_easy_setopt(handles[i].curl, CURLOPT_URL, url) != CURLE_OK) {
192 curl_mfprintf(stderr, "failed configuring easy handle - bailing out\n");
193 result = (CURLcode)2;
194 goto cleanup;
195 }
196 curl_easy_setopt(handles[i].curl, CURLOPT_HTTP_VERSION, http_version);
197 }
199 multi = curl_multi_init();
200 if(!multi) {
201 curl_mfprintf(stderr, "curl_multi_init() failed - bailing out\n");
202 result = (CURLcode)2;
203 goto cleanup;
204 }
206 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
207 if(curl_multi_add_handle(multi, handles[i].curl) != CURLM_OK) {
208 curl_mfprintf(stderr, "curl_multi_add_handle() failed - bailing out\n");
209 result = (CURLcode)2;
210 goto cleanup;
211 }
212 }
214 for(rounds = 0;; rounds++) {
215 curl_mfprintf(stderr, "INFO: multi_perform round %d\n", rounds);
216 if(curl_multi_perform(multi, &still_running) != CURLM_OK) {
217 curl_mfprintf(stderr, "curl_multi_perform() failed - bailing out\n");
218 result = (CURLcode)2;
219 goto cleanup;
220 }
222 if(!still_running) {
223 int as_expected = 1;
224 curl_mfprintf(stderr, "INFO: no more handles running\n");
225 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
226 if(!handles[i].paused) {
227 curl_mfprintf(stderr, "ERROR: [%zu] NOT PAUSED\n", i);
228 as_expected = 0;
229 }
230 else if(handles[i].paused != 1) {
231 curl_mfprintf(stderr, "ERROR: [%zu] PAUSED %d times!\n",
232 i, handles[i].paused);
233 as_expected = 0;
234 }
235 else if(!handles[i].resumed) {
236 curl_mfprintf(stderr, "ERROR: [%zu] NOT resumed!\n", i);
237 as_expected = 0;
238 }
239 else if(handles[i].errored != 1) {
240 curl_mfprintf(stderr, "ERROR: [%zu] NOT errored once, %d instead!\n",
241 i, handles[i].errored);
242 as_expected = 0;
243 }
244 }
245 if(!as_expected) {
246 curl_mfprintf(stderr, "ERROR: handles not in expected state "
247 "after %d rounds\n", rounds);
248 result = (CURLcode)1;
249 }
250 break;
251 }
253 if(curl_multi_poll(multi, NULL, 0, 100, &numfds) != CURLM_OK) {
254 curl_mfprintf(stderr, "curl_multi_poll() failed - bailing out\n");
255 result = (CURLcode)2;
256 goto cleanup;
257 }
259 /* !checksrc! disable EQUALSNULL 1 */
260 while((msg = curl_multi_info_read(multi, &msgs_left)) != NULL) {
261 if(msg->msg == CURLMSG_DONE) {
262 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
263 if(msg->easy_handle == handles[i].curl &&
264 (handles[i].paused != 1 || !handles[i].resumed)) {
265 curl_mfprintf(stderr, "ERROR: [%zu] done, paused=%d, "
266 "resumed=%d, result %d - wtf?\n", i,
267 handles[i].paused,
268 handles[i].resumed, (int)msg->data.result);
269 result = (CURLcode)1;
270 goto cleanup;
271 }
272 }
273 }
274 }
276 /* Successfully paused? */
277 if(!all_paused) {
278 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
279 if(!handles[i].paused) {
280 break;
281 }
282 }
283 all_paused = (i == CURL_ARRAYSIZE(handles));
284 if(all_paused) {
285 curl_mfprintf(stderr, "INFO: all transfers paused\n");
286 /* give transfer some rounds to mess things up */
287 resume_round = rounds + 2;
288 }
289 }
290 if(resume_round > 0 && rounds == resume_round) {
291 /* time to resume */
292 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
293 curl_mfprintf(stderr, "INFO: [%zu] resumed\n", i);
294 handles[i].resumed = 1;
295 curl_easy_pause(handles[i].curl, CURLPAUSE_CONT);
296 }
297 }
298 }
300cleanup:
302 for(i = 0; i < CURL_ARRAYSIZE(handles); i++) {
303 curl_multi_remove_handle(multi, handles[i].curl);
304 curl_easy_cleanup(handles[i].curl);
305 }
307 curl_slist_free_all(resolve);
308 curl_free(host);
309 curl_free(port);
310 curl_url_cleanup(cu);
311 curl_multi_cleanup(multi);
312 curl_global_cleanup();
314 return result;
315}
Diagnostics4 git calls · 213 ms
CallStatusSizeTime0213 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 · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=206 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 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.0 KiB206 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3084 git.response.cache=MISS git.response.duration_ms=206 git.fetch.wants=3663d841f022dc58140b8a7da9b9751c80065f3d 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=3084 git.pkt.payload.max=3063 git.sideband.band1.bytes=3062 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
- a5e2db046f7ac125
- Request
- 96e559cf…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format