Artifactspublic-v0

curl

master
ply4 git calls417 ms290 KiB2 cachedprotocol v2
250 lines7.2 KiBRaw
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 "tool_setup.h"
26#ifndef CURL_DISABLE_IPFS
28#include "tool_cfgable.h"
29#include "tool_msgs.h"
30#include "tool_ipfs.h"
32/* input string ends in slash? */
33static bool has_trailing_slash(const char *input)
35 size_t len = strlen(input);
36 return len && input[len - 1] == '/';
39static char *ipfs_gateway(void)
41 char *ipfs_path_c = NULL;
42 char *gateway_composed_c = NULL;
43 FILE *gfile = NULL;
44 char *gateway_env = getenv("IPFS_GATEWAY");
46 if(gateway_env)
47 return curlx_strdup(gateway_env);
49 /* Try to find the gateway in the IPFS data folder. */
50 ipfs_path_c = curl_getenv("IPFS_PATH");
52 if(!ipfs_path_c) {
53 char *home = getenv("HOME");
54 /* fallback to "~/.ipfs", as that is the default location. */
55 if(home && *home)
56 ipfs_path_c = curl_maprintf("%s/.ipfs/", home);
57 if(!ipfs_path_c)
58 goto fail;
59 }
61 gateway_composed_c =
62 curl_maprintf("%s%sgateway", ipfs_path_c,
63 has_trailing_slash(ipfs_path_c) ? "" : "/");
65 if(!gateway_composed_c)
66 goto fail;
68 gfile = curlx_fopen(gateway_composed_c, FOPEN_READTEXT);
69 curl_free(gateway_composed_c);
71 if(gfile) {
72 int c;
73 struct dynbuf dyn;
74 char *gateway = NULL;
75 curlx_dyn_init(&dyn, MAX_GATEWAY_URL_LEN);
77 /* get the first line of the gateway file, ignore the rest */
78 while((c = getc(gfile)) != EOF && c != '\n' && c != '\r') {
79 char c_char = (char)c;
80 if(curlx_dyn_addn(&dyn, &c_char, 1))
81 goto fail;
82 }
84 if(curlx_dyn_len(&dyn))
85 gateway = curlx_dyn_ptr(&dyn);
87 curl_free(ipfs_path_c);
88 curlx_fclose(gfile);
90 return gateway;
91 }
92fail:
93 if(gfile)
94 curlx_fclose(gfile);
95 curl_free(ipfs_path_c);
96 return NULL;
99/*
100 * Rewrite ipfs://<cid> and ipns://<cid> to an HTTP(S)
101 * URL that can be handled by an IPFS gateway.
102 */
103CURLcode ipfs_url_rewrite(CURLU *uh, const char *protocol, char **url,
104 struct OperationConfig *config)
106 CURLcode result = CURLE_URL_MALFORMAT;
107 CURLUcode getResult;
108 char *gateway = NULL;
109 char *gwhost = NULL;
110 char *gwpath = NULL;
111 char *gwquery = NULL;
112 char *gwscheme = NULL;
113 char *gwport = NULL;
114 char *inputpath = NULL;
115 char *cid = NULL;
116 char *pathbuffer = NULL;
117 char *cloneurl;
118 CURLU *gatewayurl = curl_url();
120 if(!gatewayurl) {
121 result = CURLE_FAILED_INIT;
122 goto clean;
123 }
125 /* keep the CID percent-encoded, it goes into the path (see note below) */
126 getResult = curl_url_get(uh, CURLUPART_HOST, &cid, 0);
127 if(getResult || !cid)
128 goto clean;
130 /* We might have a --ipfs-gateway argument. Check it first and use it. Error
131 * if we do have something but if it is an invalid URL.
132 */
133 if(config->ipfs_gateway) {
134 if(!curl_url_set(gatewayurl, CURLUPART_URL, config->ipfs_gateway,
135 CURLU_GUESS_SCHEME)) {
136 gateway = curlx_strdup(config->ipfs_gateway);
137 if(!gateway) {
138 result = CURLE_URL_MALFORMAT;
139 goto clean;
140 }
141 }
142 else {
143 result = CURLE_BAD_FUNCTION_ARGUMENT;
144 goto clean;
145 }
146 }
147 else {
148 gateway = ipfs_gateway();
149 if(!gateway) {
150 result = CURLE_FILE_COULDNT_READ_FILE;
151 goto clean;
152 }
154 if(curl_url_set(gatewayurl, CURLUPART_URL, gateway, 0)) {
155 result = CURLE_URL_MALFORMAT;
156 goto clean;
157 }
158 }
160 /* check for unsupported gateway parts */
161 if(curl_url_get(gatewayurl, CURLUPART_QUERY, &gwquery, 0) !=
162 CURLUE_NO_QUERY) {
163 result = CURLE_URL_MALFORMAT;
164 goto clean;
165 }
167 /* get gateway parts */
168 if(curl_url_get(gatewayurl, CURLUPART_HOST, &gwhost, CURLU_URLDECODE) ||
169 curl_url_get(gatewayurl, CURLUPART_SCHEME, &gwscheme, CURLU_URLDECODE) ||
170 curl_url_get(gatewayurl, CURLUPART_PATH, &gwpath, 0))
171 goto clean;
173 /* only keep a port the gateway URL sets, so that a later scheme change
174 (like an HSTS upgrade) gets the default port of the new scheme */
175 getResult = curl_url_get(gatewayurl, CURLUPART_PORT, &gwport,
176 0);
177 if(getResult && (getResult != CURLUE_NO_PORT))
178 goto clean;
180 /* Get the user path without decoding it, and build the new path below from
181 these still-encoded parts. Decoding here would turn an encoded slash (%2f)
182 into a real separator that the parser's earlier dot-segment cleanup never
183 saw, so a ".." could then climb out of the /<protocol>/<cid> namespace
184 when the final URL is parsed. Keeping every percent-encoded byte encoded
185 means no new separators appear and nothing new gets removed. */
186 if(curl_url_get(uh, CURLUPART_PATH, &inputpath, 0))
187 goto clean;
188 /* inputpath might be NULL or a valid pointer now */
190 /* set gateway parts in input URL */
191 if(curl_url_set(uh, CURLUPART_SCHEME, gwscheme, CURLU_URLENCODE) ||
192 curl_url_set(uh, CURLUPART_HOST, gwhost, CURLU_URLENCODE) ||
193 curl_url_set(uh, CURLUPART_PORT, gwport, CURLU_URLENCODE))
194 goto clean;
196 /* if the input path is a slash, clear it */
197 if(inputpath && (inputpath[0] == '/') && !inputpath[1])
198 *inputpath = '\0';
200 pathbuffer = curl_maprintf("%s%s%s/%s%s", gwpath,
201 has_trailing_slash(gwpath) ? "" : "/",
202 protocol, cid,
203 inputpath ? inputpath : "");
204 if(!pathbuffer ||
205 curl_url_set(uh, CURLUPART_PATH, pathbuffer, 0))
206 goto clean;
208 /* Free whatever it has now, rewriting is next */
209 curlx_safefree(*url);
211 if(curl_url_get(uh, CURLUPART_URL, &cloneurl, CURLU_URLENCODE)) {
212 goto clean;
213 }
214 /* we need to strdup the URL so that we can call curlx_free() on it later */
215 *url = curlx_strdup(cloneurl);
216 curl_free(cloneurl);
217 if(!*url)
218 goto clean;
220 result = CURLE_OK;
222clean:
223 curlx_free(gateway);
224 curl_free(gwhost);
225 curl_free(gwpath);
226 curl_free(gwquery);
227 curl_free(inputpath);
228 curl_free(gwscheme);
229 curl_free(gwport);
230 curl_free(cid);
231 curl_free(pathbuffer);
232 curl_url_cleanup(gatewayurl);
233 {
234 switch(result) {
235 case CURLE_URL_MALFORMAT:
236 helpf("malformed target URL");
237 break;
238 case CURLE_FILE_COULDNT_READ_FILE:
239 helpf("IPFS automatic gateway detection failed");
240 break;
241 case CURLE_BAD_FUNCTION_ARGUMENT:
242 helpf("--ipfs-gateway was given a malformed URL");
243 break;
244 default:
245 break;
246 }
247 }
248 return result;
250#endif /* !CURL_DISABLE_IPFS */
Diagnostics4 git calls · 417 ms
CallStatusSizeTime0417 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=411
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=86
Open pack map
fetch2002.8 KiB411 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2840
git.response.cache=MISS
git.response.duration_ms=411
git.fetch.wants=a3f55a94721760af8367496b58d624bb404e3ec2
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=2840
git.pkt.payload.max=2819
git.sideband.band1.bytes=2818
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
a5e171c04ecb6102
Request
feec974b…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format