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#include "first.h"
26#include "testtrace.h"
28static FILE *out_download = NULL;
30static int setup_h2_serverpush(CURL *curl, const char *url)
31{
32 out_download = curlx_fopen("download_0.data", "wb");
33 if(!out_download)
34 return 1; /* failed */
36 curl_easy_setopt(curl, CURLOPT_URL, url);
37 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
38 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
39 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
41 curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_download);
43 /* please be verbose */
44 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
45 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
46 curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
48 /* wait for pipe connection to confirm */
49 curl_easy_setopt(curl, CURLOPT_PIPEWAIT, 1L);
51 return 0; /* all is good */
52}
54static FILE *out_push = NULL;
56/* called when there is an incoming push */
57static int server_push_callback(CURL *parent,
58 CURL *curl,
59 size_t num_headers,
60 struct curl_pushheaders *headers,
61 void *userp)
62{
63 const char *headp;
64 size_t i;
65 int *transfers = (int *)userp;
66 char filename[128];
67 static unsigned int count = 0;
69 (void)parent;
71 curl_msnprintf(filename, sizeof(filename) - 1, "push%u", count++);
73 /* here's a new stream, save it in a new file for each new push */
74 out_push = curlx_fopen(filename, "wb");
75 if(!out_push) {
76 /* if we cannot save it, deny it */
77 curl_mfprintf(stderr, "Failed to create output file for push\n");
78 return CURL_PUSH_DENY;
79 }
81 /* write to this file */
82 curl_easy_setopt(curl, CURLOPT_WRITEDATA, out_push);
84 curl_mfprintf(stderr, "**** push callback approves stream %u, "
85 "got %zu headers!\n", count, num_headers);
87 for(i = 0; i < num_headers; i++) {
88 headp = curl_pushheader_bynum(headers, i);
89 curl_mfprintf(stderr, "**** header %zu: %s\n", i, headp);
90 }
92 headp = curl_pushheader_byname(headers, ":path");
93 if(headp) {
94 curl_mfprintf(stderr, "**** The PATH is %s\n",
95 headp /* skip :path + colon */);
96 }
98 (*transfers)++; /* one more */
100 return CURL_PUSH_OK;
101}
103/*
104 * Download a file over HTTP/2, take care of server push.
105 */
106static CURLcode test_cli_h2_serverpush(const char *URL)
107{
108 CURL *curl = NULL;
109 CURLM *multi;
110 int transfers = 1; /* we start with one */
111 CURLcode result = CURLE_OK;
113 debug_config.nohex = TRUE;
114 debug_config.tracetime = FALSE;
116 if(!URL) {
117 curl_mfprintf(stderr, "need URL as argument\n");
118 return (CURLcode)2;
119 }
121 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
122 curl_mfprintf(stderr, "curl_global_init() failed\n");
123 return (CURLcode)3;
124 }
126 multi = curl_multi_init();
127 if(!multi) {
128 result = (CURLcode)1;
129 goto cleanup;
130 }
132 curl = curl_easy_init();
133 if(!curl) {
134 result = (CURLcode)1;
135 goto cleanup;
136 }
138 if(setup_h2_serverpush(curl, URL)) {
139 curl_mfprintf(stderr, "failed\n");
140 result = (CURLcode)1;
141 goto cleanup;
142 }
144 curl_multi_setopt(multi, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
145 curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, server_push_callback);
146 curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &transfers);
148 curl_multi_add_handle(multi, curl);
150 do {
151 struct CURLMsg *m;
152 int still_running; /* keep number of running handles */
153 CURLMcode mresult = curl_multi_perform(multi, &still_running);
155 if(still_running)
156 /* wait for activity, timeout or "nothing" */
157 mresult = curl_multi_poll(multi, NULL, 0, 1000, NULL);
159 if(mresult)
160 break;
162 /*
163 * A little caution when doing server push is that libcurl itself has
164 * created and added one or more easy handles but we need to clean them up
165 * when we are done.
166 */
167 do {
168 int msgq = 0;
169 m = curl_multi_info_read(multi, &msgq);
170 if(m && (m->msg == CURLMSG_DONE)) {
171 CURL *easy = m->easy_handle;
172 if(easy != curl) {
173 char *redirect_url = NULL;
174 if(!curl_easy_getinfo(easy, CURLINFO_REDIRECT_URL,
175 &redirect_url) && redirect_url)
176 curl_mfprintf(stderr, "**** push redirect URL: %s\n",
177 redirect_url);
178 }
179 transfers--;
180 curl_multi_remove_handle(multi, easy);
181 curl_easy_cleanup(easy);
182 }
183 } while(m);
185 } while(transfers); /* as long as we have transfers going */
187cleanup:
189 curl_multi_cleanup(multi);
191 if(out_download)
192 curlx_fclose(out_download);
193 if(out_push)
194 curlx_fclose(out_push);
196 curl_global_cleanup();
198 return result;
199}
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs 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=3 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
fetch2002.2 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=2274 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=4c7832372e7e95af712e2f93d3e1e5e651dc1a7d 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=2274 git.pkt.payload.max=2253 git.sideband.band1.bytes=2252 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
- a5e2ba4e3a45cf46
- Request
- 130e3e12…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format