Artifactspublic-v0

curl

master
ply4 git calls223 ms290 KiB2 cachedprotocol v2
347 lines9.6 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 "curl_setup.h"
26#ifndef CURL_DISABLE_HTTP
28#include "urldata.h"
29#include "http.h"
30#include "http1.h"
31#include "urlapi-int.h"
34#define H1_MAX_URL_LEN (8 * 1024)
36void Curl_h1_req_parse_init(struct h1_req_parser *parser, size_t max_line_len)
38 memset(parser, 0, sizeof(*parser));
39 parser->max_line_len = max_line_len;
40 curlx_dyn_init(&parser->scratch, max_line_len);
43void Curl_h1_req_parse_free(struct h1_req_parser *parser)
45 if(parser) {
46 Curl_http_req_free(parser->req);
47 curlx_dyn_free(&parser->scratch);
48 parser->req = NULL;
49 parser->done = FALSE;
50 }
53static CURLcode trim_line(struct h1_req_parser *parser, int options)
55 DEBUGASSERT(parser->line);
56 if(parser->line_len) {
57 if(parser->line[parser->line_len - 1] == '\n')
58 --parser->line_len;
59 if(parser->line_len) {
60 if(parser->line[parser->line_len - 1] == '\r')
61 --parser->line_len;
62 else if(options & H1_PARSE_OPT_STRICT)
63 return CURLE_URL_MALFORMAT;
64 }
65 else if(options & H1_PARSE_OPT_STRICT)
66 return CURLE_URL_MALFORMAT;
67 }
68 else if(options & H1_PARSE_OPT_STRICT)
69 return CURLE_URL_MALFORMAT;
71 if(parser->line_len > parser->max_line_len) {
72 return CURLE_URL_MALFORMAT;
73 }
74 return CURLE_OK;
77static CURLcode detect_line(struct h1_req_parser *parser,
78 const uint8_t *buf, const size_t buflen,
79 size_t *pnread)
81 const char *line_end;
83 DEBUGASSERT(!parser->line);
84 *pnread = 0;
85 line_end = memchr(buf, '\n', buflen);
86 if(!line_end)
87 return CURLE_AGAIN;
88 parser->line = (const char *)buf;
89 parser->line_len = line_end - parser->line + 1;
90 *pnread = parser->line_len;
91 return CURLE_OK;
94static CURLcode next_line(struct h1_req_parser *parser,
95 const uint8_t *buf, const size_t buflen, int options,
96 size_t *pnread)
98 CURLcode result;
100 *pnread = 0;
101 if(parser->line) {
102 parser->line = NULL;
103 parser->line_len = 0;
104 curlx_dyn_reset(&parser->scratch);
105 }
107 result = detect_line(parser, buf, buflen, pnread);
108 if(!result) {
109 if(curlx_dyn_len(&parser->scratch)) {
110 /* append detected line to scratch to have the complete line */
111 result = curlx_dyn_addn(&parser->scratch, parser->line,
112 parser->line_len);
113 if(result)
114 return result;
115 parser->line = curlx_dyn_ptr(&parser->scratch);
116 parser->line_len = curlx_dyn_len(&parser->scratch);
117 }
118 result = trim_line(parser, options);
119 if(result)
120 return result;
121 }
122 else if(result == CURLE_AGAIN) {
123 /* no line end in `buf`, add it to our scratch */
124 result = curlx_dyn_addn(&parser->scratch, (const unsigned char *)buf,
125 buflen);
126 *pnread = buflen;
127 }
128 return result;
131static CURLcode start_req(struct h1_req_parser *parser,
132 const char *scheme_default,
133 const char *custom_method,
134 int options)
136 const char *p, *m, *target, *hv, *scheme, *authority, *path;
137 size_t m_len, target_len, hv_len, scheme_len, authority_len, path_len;
138 size_t i;
139 CURLU *url = NULL;
140 CURLcode result = CURLE_URL_MALFORMAT; /* Use this as default fail */
142 DEBUGASSERT(!parser->req);
143 /* line must match: "METHOD TARGET HTTP_VERSION" */
144 if(custom_method && custom_method[0] &&
145 !strncmp(custom_method, parser->line, strlen(custom_method))) {
146 p = parser->line + strlen(custom_method);
147 }
148 else {
149 p = memchr(parser->line, ' ', parser->line_len);
150 if(!p || p == parser->line)
151 goto out;
152 }
154 m = parser->line;
155 m_len = p - parser->line;
156 target = p + 1;
157 target_len = hv_len = 0;
158 hv = NULL;
160 /* URL may contain spaces so scan backwards */
161 for(i = parser->line_len; i > m_len; --i) {
162 if(parser->line[i] == ' ') {
163 hv = &parser->line[i + 1];
164 hv_len = parser->line_len - i;
165 target_len = (hv - target) - 1;
166 break;
167 }
168 }
169 /* no SPACE found or empty TARGET or empty HTTP_VERSION */
170 if(!target_len || !hv_len)
171 goto out;
173 (void)hv;
175 /* The TARGET can be (rfc 9112, ch. 3.2):
176 * origin-form: path + optional query
177 * absolute-form: absolute URI
178 * authority-form: host+port for CONNECT
179 * asterisk-form: '*' for OPTIONS
180 *
181 * from TARGET, we derive `scheme` `authority` `path`
182 * origin-form -- -- TARGET
183 * absolute-form URL* URL* URL*
184 * authority-form -- TARGET --
185 * asterisk-form -- -- TARGET
186 */
187 scheme = authority = path = NULL;
188 scheme_len = authority_len = path_len = 0;
190 if(target_len == 1 && target[0] == '*') {
191 /* asterisk-form */
192 path = target;
193 path_len = target_len;
194 }
195 else if(!strncmp("CONNECT", m, m_len)) {
196 /* authority-form */
197 authority = target;
198 authority_len = target_len;
199 }
200 else if(target[0] == '/') {
201 /* origin-form */
202 path = target;
203 path_len = target_len;
204 }
205 else {
206 /* origin-form OR absolute-form */
207 CURLUcode uc;
208 char tmp[H1_MAX_URL_LEN];
210 /* default, unless we see an absolute URL */
211 path = target;
212 path_len = target_len;
214 /* URL parser wants null-termination */
215 if(target_len >= sizeof(tmp))
216 goto out;
217 memcpy(tmp, target, target_len);
218 tmp[target_len] = '\0';
219 /* See if treating TARGET as an absolute URL makes sense */
220 if(Curl_is_absolute_url(tmp, NULL, 0, FALSE)) {
221 unsigned int url_options;
223 url = curl_url();
224 if(!url) {
225 result = CURLE_OUT_OF_MEMORY;
226 goto out;
227 }
228 url_options = (CURLU_NON_SUPPORT_SCHEME |
229 CURLU_PATH_AS_IS |
230 CURLU_NO_DEFAULT_PORT);
231 if(!(options & H1_PARSE_OPT_STRICT))
232 url_options |= CURLU_ALLOW_SPACE;
233 uc = curl_url_set(url, CURLUPART_URL, tmp, url_options);
234 if(uc) {
235 goto out;
236 }
237 }
239 if(!url && (options & H1_PARSE_OPT_STRICT)) {
240 /* we should have an absolute URL or have seen `/` earlier */
241 goto out;
242 }
243 }
245 if(url) {
246 result = Curl_http_req_make2(&parser->req, m, m_len, url, scheme_default);
247 }
248 else {
249 if(!scheme && scheme_default) {
250 scheme = scheme_default;
251 scheme_len = strlen(scheme_default);
252 }
253 result = Curl_http_req_make(&parser->req, m, m_len, scheme, scheme_len,
254 authority, authority_len, path, path_len);
255 }
257out:
258 curl_url_cleanup(url);
259 return result;
262CURLcode Curl_h1_req_parse_read(struct h1_req_parser *parser,
263 const uint8_t *buf, size_t buflen,
264 const char *scheme_default,
265 const char *custom_method,
266 int options, size_t *pnread)
268 CURLcode result = CURLE_OK;
269 size_t nread;
271 *pnread = 0;
273 DEBUGASSERT(buf);
274 if(!buf)
275 return CURLE_BAD_FUNCTION_ARGUMENT;
277 while(!parser->done) {
278 result = next_line(parser, buf, buflen, options, &nread);
279 if(result) {
280 if(result == CURLE_AGAIN)
281 result = CURLE_OK;
282 goto out;
283 }
285 /* Consume this line */
286 *pnread += nread;
287 buf += nread;
288 buflen -= nread;
290 if(!parser->line) {
291 /* consumed bytes, but line not complete */
292 if(!buflen)
293 goto out;
294 }
295 else if(!parser->req) {
296 result = start_req(parser, scheme_default, custom_method, options);
297 if(result)
298 goto out;
299 }
300 else if(parser->line_len == 0) {
301 /* last, empty line, we are finished */
302 if(!parser->req) {
303 result = CURLE_URL_MALFORMAT;
304 goto out;
305 }
306 parser->done = TRUE;
307 curlx_dyn_reset(&parser->scratch);
308 /* last chance adjustments */
309 }
310 else {
311 result = Curl_dynhds_h1_add_line(&parser->req->headers,
312 parser->line, parser->line_len);
313 if(result)
314 goto out;
315 }
316 }
318out:
319 return result;
322CURLcode Curl_h1_req_write_head(struct httpreq *req, int http_minor,
323 struct dynbuf *dbuf)
325 CURLcode result;
327 result = curlx_dyn_addf(dbuf, "%s %s%s%s%s HTTP/1.%d\r\n",
328 req->method,
329 req->scheme ? req->scheme : "",
330 req->scheme ? "://" : "",
331 req->authority ? req->authority : "",
332 req->path ? req->path : "",
333 http_minor);
334 if(result)
335 goto out;
337 result = Curl_dynhds_h1_dprint(&req->headers, dbuf);
338 if(result)
339 goto out;
341 result = curlx_dyn_addn(dbuf, STRCONST("\r\n"));
343out:
344 return result;
347#endif /* !CURL_DISABLE_HTTP */
Diagnostics4 git calls · 223 ms
CallStatusSizeTime0223 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=218
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=86
Open pack map
fetch2003.2 KiB218 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=3228
git.response.cache=MISS
git.response.duration_ms=218
git.fetch.wants=60ad32ce89b95832a753d01baa75303aac013b7b
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=3228
git.pkt.payload.max=3207
git.sideband.band1.bytes=3206
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
a5e22c5e5e782a83
Request
c5cb915b…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format