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 "unitcheck.h"
26#ifndef CURL_DISABLE_HTTP
27#include "urldata.h"
28#include "http1.h"
29#include "curl_trc.h"
31static void check_eq(const char *s, const char *exp_s, const char *name)
32{
33 if(s && exp_s) {
34 if(strcmp(s, exp_s)) {
35 curl_mfprintf(stderr, "expected %s: '%s' but got '%s'\n",
36 name, exp_s, s);
37 fail("unexpected req component");
38 }
39 }
40 else if(!s && exp_s) {
41 curl_mfprintf(stderr, "expected %s: '%s' but got NULL\n", name, exp_s);
42 fail("unexpected req component");
43 }
44 else if(s && !exp_s) {
45 curl_mfprintf(stderr, "expected %s: NULL but got '%s'\n", name, s);
46 fail("unexpected req component");
47 }
48}
50struct tcase {
51 const char * const *input;
52 const char *default_scheme;
53 const char *custom_method;
54 const char *method;
55 const char *scheme;
56 const char *authority;
57 const char *path;
58 size_t header_count;
59 size_t input_remain;
60};
62static void parse_success(const struct tcase *t)
63{
64 struct h1_req_parser p;
65 const uint8_t *buf;
66 size_t buflen, i, in_len, in_consumed;
67 CURLcode result;
68 size_t nread;
70 Curl_h1_req_parse_init(&p, 1024);
71 in_len = in_consumed = 0;
72 for(i = 0; t->input[i]; ++i) {
73 buf = (const uint8_t *)t->input[i];
74 buflen = strlen(t->input[i]);
75 in_len += buflen;
76 result = Curl_h1_req_parse_read(&p, buf, buflen, t->default_scheme,
77 t->custom_method, 0, &nread);
78 if(result) {
79 curl_mfprintf(stderr, "got result %d parsing: '%s'\n", (int)result, buf);
80 fail("error consuming");
81 }
82 in_consumed += nread;
83 if(nread != buflen && !p.done) {
84 curl_mfprintf(stderr, "only %zu/%zu consumed for: '%s'\n",
85 nread, buflen, buf);
86 fail("not all consumed");
87 }
88 }
90 fail_if(!p.done, "end not detected");
91 fail_if(!p.req, "not request created");
92 if(t->input_remain != (in_len - in_consumed)) {
93 curl_mfprintf(stderr, "expected %zu input bytes to remain, but got %zu\n",
94 t->input_remain, in_len - in_consumed);
95 fail("unexpected input consumption");
96 }
97 if(p.req) {
98 check_eq(p.req->method, t->method, "method");
99 check_eq(p.req->scheme, t->scheme, "scheme");
100 check_eq(p.req->authority, t->authority, "authority");
101 check_eq(p.req->path, t->path, "path");
102 if(Curl_dynhds_count(&p.req->headers) != t->header_count) {
103 curl_mfprintf(stderr, "expected %zu headers but got %zu\n",
104 t->header_count, Curl_dynhds_count(&p.req->headers));
105 fail("unexpected req header count");
106 }
107 }
109 Curl_h1_req_parse_free(&p);
110}
111#endif
113static CURLcode test_unit2603(const char *arg)
114{
115 UNITTEST_BEGIN_SIMPLE
117#ifndef CURL_DISABLE_HTTP
118 static const char * const T1_INPUT[] = {
119 "GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
120 NULL,
121 };
122 static const struct tcase TEST1a = {
123 T1_INPUT, NULL, NULL, "GET", NULL, NULL, "/path", 1, 0
124 };
125 static const struct tcase TEST1b = {
126 T1_INPUT, "https", NULL, "GET", "https", NULL, "/path", 1, 0
127 };
129 static const char * const T2_INPUT[] = {
130 "GET /path HTT",
131 "P/1.1\r\nHost: te",
132 "st.curl.se\r\n\r",
133 "\n12345678",
134 NULL,
135 };
136 static const struct tcase TEST2 = {
137 T2_INPUT, NULL, NULL, "GET", NULL, NULL, "/path", 1, 8
138 };
140 static const char * const T3_INPUT[] = {
141 "GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
142 "\nUser-Agent: xxx\r\n\r\n",
143 NULL,
144 };
145 static const struct tcase TEST3a = {
146 T3_INPUT, NULL, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
147 };
149 static const char * const T4_INPUT[] = {
150 "CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
151 "User-Agent: xxx\r\n",
152 "nothing: \r\n\r\n\n\n",
153 NULL,
154 };
155 static const struct tcase TEST4a = {
156 T4_INPUT, NULL, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
157 };
159 static const char * const T6_INPUT[] = {
160 "PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
161 NULL,
162 };
163 static const struct tcase TEST6a = {
164 T6_INPUT, NULL, NULL, "PUT", NULL, NULL, "/path", 1, 3
165 };
167 /* test a custom method with space, #19543 */
168 static const char * const T7_INPUT[] = {
169 "IN SANE /path HTTP/1.1\r\nContent-Length: 0\r\n\r\n",
170 NULL,
171 };
172 static const struct tcase TEST7a = {
173 T7_INPUT, NULL, NULL, "IN", NULL, NULL, "SANE /path", 1, 0
174 };
175 static const struct tcase TEST7b = {
176 T7_INPUT, NULL, "IN SANE", "IN SANE", NULL, NULL, "/path", 1, 0
177 };
179 parse_success(&TEST1a);
180 parse_success(&TEST1b);
181 parse_success(&TEST2);
182 parse_success(&TEST3a);
183 parse_success(&TEST4a);
184 parse_success(&TEST6a);
185 parse_success(&TEST7a);
186 parse_success(&TEST7b);
187#endif
189 UNITTEST_END_SIMPLE
190}
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=2 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
fetch2001.9 KiB · hit29 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=29 git.response.bytes=1934 git.response.cache=HIT git.response.duration_ms=29 git.fetch.wants=0780567da1fc83e85df140fe9b53260b82e5aeeb 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=1934 git.pkt.payload.max=1913 git.sideband.band1.bytes=1912 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
- a5e1fc25c983a9c0
- Request
- 7dfc1082…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format