GitLabgitlab-org

cli

main
ply7 git calls36 ms101 KiB5 cachedprotocol v2
762 lines20 KiBRaw
1//go:build !integration
3package api
5import (
6 "bytes"
7 "encoding/json"
8 "fmt"
9 "io"
10 "mime"
11 "mime/multipart"
12 "net/http"
13 "os"
14 "path/filepath"
15 "strings"
16 "testing"
18 "github.com/stretchr/testify/assert"
19 "github.com/stretchr/testify/require"
21 "gitlab.com/gitlab-org/cli/internal/api"
22 "gitlab.com/gitlab-org/cli/internal/testing/cmdtest"
23 "gitlab.com/gitlab-org/cli/test"
26func Test_groupGraphQLVariables(t *testing.T) {
27 tests := []struct {
28 name string
29 args map[string]any
30 want map[string]any
31 }{
32 {
33 name: "empty",
34 args: map[string]any{},
35 want: map[string]any{},
36 },
37 {
38 name: "query only",
39 args: map[string]any{
40 "query": "QUERY",
41 },
42 want: map[string]any{
43 "query": "QUERY",
44 },
45 },
46 {
47 name: "variables only",
48 args: map[string]any{
49 "name": "gitlab-bot",
50 },
51 want: map[string]any{
52 "variables": map[string]any{
53 "name": "gitlab-bot",
54 },
55 },
56 },
57 {
58 name: "query + variables",
59 args: map[string]any{
60 "query": "QUERY",
61 "name": "gitlab-bot",
62 "power": 9001,
63 },
64 want: map[string]any{
65 "query": "QUERY",
66 "variables": map[string]any{
67 "name": "gitlab-bot",
68 "power": 9001,
69 },
70 },
71 },
72 {
73 name: "query + operationName + variables",
74 args: map[string]any{
75 "query": "query Q1{} query Q2{}",
76 "operationName": "Q1",
77 "power": 9001,
78 },
79 want: map[string]any{
80 "query": "query Q1{} query Q2{}",
81 "operationName": "Q1",
82 "variables": map[string]any{
83 "power": 9001,
84 },
85 },
86 },
87 {
88 name: "query + JSON array variable",
89 args: map[string]any{
90 "query": "QUERY",
91 "topics": []any{"my-topic", "GitLab"},
92 },
93 want: map[string]any{
94 "query": "QUERY",
95 "variables": map[string]any{
96 "topics": []any{"my-topic", "GitLab"},
97 },
98 },
99 },
100 {
101 name: "query + JSON object variable",
102 args: map[string]any{
103 "query": "QUERY",
104 "config": map[string]any{"enabled": true},
105 },
106 want: map[string]any{
107 "query": "QUERY",
108 "variables": map[string]any{
109 "config": map[string]any{"enabled": true},
110 },
111 },
112 },
113 }
114 for _, tt := range tests {
115 t.Run(tt.name, func(t *testing.T) {
116 got := groupGraphQLVariables(tt.args)
117 assert.Equal(t, tt.want, got)
118 })
119 }
122type roundTripFunc func(r *http.Request) (*http.Response, error)
124func (s roundTripFunc) RoundTrip(r *http.Request) (*http.Response, error) {
125 return s(r)
128func Test_httpRequest(t *testing.T) {
129 test.ClearEnvironmentVariables(t)
131 client := &http.Client{}
132 client.Transport = roundTripFunc(func(req *http.Request) (*http.Response, error) {
133 t.Log("Tsti")
134 return &http.Response{
135 StatusCode: http.StatusOK,
136 Request: req,
137 }, nil
138 })
140 type args struct {
141 host string
142 method string
143 p string
144 params any
145 headers []string
146 rawBodyIsJSON bool
147 }
148 type expects struct {
149 method string
150 u string
151 body string
152 headers string
153 }
154 tests := []struct {
155 name string
156 args args
157 want expects
158 wantErr bool
159 }{
160 {
161 name: "simple GET",
162 args: args{
163 host: "gitlab.com",
164 method: http.MethodGet,
165 p: "projects/gitlab-com%2Fwww-gitlab-com",
166 params: nil,
167 headers: []string{},
168 },
169 wantErr: false,
170 want: expects{
171 method: http.MethodGet,
172 u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com",
173 body: "",
174 headers: "Private-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
175 },
176 },
177 {
178 name: "GET with leading slash",
179 args: args{
180 host: "gitlab.com",
181 method: http.MethodGet,
182 p: "/projects/gitlab-com%2Fwww-gitlab-com",
183 params: nil,
184 headers: []string{},
185 },
186 wantErr: false,
187 want: expects{
188 method: http.MethodGet,
189 u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com",
190 body: "",
191 headers: "Private-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
192 },
193 },
194 {
195 name: "GET with params",
196 args: args{
197 host: "gitlab.com",
198 method: http.MethodGet,
199 p: "projects/gitlab-com%2Fwww-gitlab-com",
200 params: map[string]any{
201 "a": "b",
202 },
203 headers: []string{},
204 },
205 wantErr: false,
206 want: expects{
207 method: http.MethodGet,
208 u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com?a=b",
209 body: "",
210 headers: "Private-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
211 },
212 },
213 {
214 // DELETE is a query method too, so its fields go on the URL and it
215 // sends no JSON body, which the absent Content-Type header shows.
216 name: "DELETE with params",
217 args: args{
218 host: "gitlab.com",
219 method: http.MethodDelete,
220 p: "projects/gitlab-com%2Fwww-gitlab-com",
221 params: map[string]any{
222 "a": "b",
223 },
224 headers: []string{},
225 },
226 wantErr: false,
227 want: expects{
228 method: http.MethodDelete,
229 u: "https://gitlab.com/api/v4/projects/gitlab-com%2Fwww-gitlab-com?a=b",
230 body: "",
231 headers: "Private-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
232 },
233 },
234 {
235 name: "POST GraphQL",
236 args: args{
237 host: "gitlab.com",
238 method: http.MethodPost,
239 p: "graphql",
240 params: map[string]any{
241 "a": []byte("b"),
242 },
243 headers: []string{},
244 },
245 wantErr: false,
246 want: expects{
247 method: http.MethodPost,
248 u: "https://gitlab.com/api/graphql",
249 body: `{"variables":{"a":"b"}}`,
250 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
251 },
252 },
253 {
254 // json.Number must survive json.Marshal on the GraphQL body path, or
255 // an ID beyond float64's exact range would be silently rounded.
256 name: "POST GraphQL with a large integer variable keeps full precision",
257 args: args{
258 host: "gitlab.com",
259 method: http.MethodPost,
260 p: "graphql",
261 params: map[string]any{
262 "query": "mutation($iid: ID!) { foo(iid: $iid) { id } }",
263 "iid": json.Number("9007199254740993"),
264 },
265 headers: []string{},
266 },
267 wantErr: false,
268 want: expects{
269 method: http.MethodPost,
270 u: "https://gitlab.com/api/graphql",
271 body: `{"query":"mutation($iid: ID!) { foo(iid: $iid) { id } }","variables":{"iid":9007199254740993}}`,
272 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
273 },
274 },
275 {
276 name: "POST with body and type",
277 args: args{
278 host: "gitlab.com",
279 method: http.MethodPost,
280 p: "projects",
281 params: bytes.NewBufferString("CUSTOM"),
282 headers: []string{
283 "content-type: text/plain",
284 "accept: application/json",
285 },
286 },
287 wantErr: false,
288 want: expects{
289 method: http.MethodPost,
290 u: "https://gitlab.com/api/v4/projects",
291 body: `CUSTOM`,
292 headers: "Accept: application/json\r\nContent-Type: text/plain\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
293 },
294 },
295 {
296 name: "POST with JSON array field",
297 args: args{
298 host: "gitlab.com",
299 method: http.MethodPost,
300 p: "projects",
301 params: map[string]any{"scopes": []any{"api", "read_api"}},
302 headers: []string{
303 "content-type: application/json",
304 "accept: application/json",
305 },
306 },
307 wantErr: false,
308 want: expects{
309 method: http.MethodPost,
310 u: "https://gitlab.com/api/v4/projects",
311 body: `{"scopes":["api","read_api"]}`,
312 headers: "Accept: application/json\r\nContent-Type: application/json\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
313 },
314 },
315 {
316 name: "POST with JSON object field",
317 args: args{
318 host: "gitlab.com",
319 method: http.MethodPost,
320 p: "projects",
321 params: map[string]any{"config": map[string]any{"enabled": true, "mode": "strict"}},
322 headers: []string{},
323 },
324 wantErr: false,
325 want: expects{
326 method: http.MethodPost,
327 u: "https://gitlab.com/api/v4/projects",
328 body: `{"config":{"enabled":true,"mode":"strict"}}`,
329 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
330 },
331 },
332 {
333 // A percent-encoded bracket is not a bracket, so parseFields lets the
334 // name through and it reaches the body as the literal key it was typed as.
335 name: "POST with a percent-encoded bracket in the field name",
336 args: args{
337 host: "gitlab.com",
338 method: http.MethodPost,
339 p: "projects",
340 params: map[string]any{"ids%5B%5D": "1"},
341 headers: []string{},
342 },
343 wantErr: false,
344 want: expects{
345 method: http.MethodPost,
346 u: "https://gitlab.com/api/v4/projects",
347 body: `{"ids%5B%5D":"1"}`,
348 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
349 },
350 },
351 {
352 name: "POST with non-array string value unchanged",
353 args: args{
354 host: "gitlab.com",
355 method: http.MethodPost,
356 p: "projects",
357 params: map[string]any{"name": "my-project"},
358 headers: []string{},
359 },
360 wantErr: false,
361 want: expects{
362 method: http.MethodPost,
363 u: "https://gitlab.com/api/v4/projects",
364 body: `{"name":"my-project"}`,
365 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
366 },
367 },
368 {
369 name: "raw body announced as JSON gets the default content type",
370 args: args{
371 host: "gitlab.com",
372 method: http.MethodPost,
373 p: "markdown",
374 params: strings.NewReader(`{"text":"hello"}`),
375 headers: []string{},
376 rawBodyIsJSON: true,
377 },
378 wantErr: false,
379 want: expects{
380 method: http.MethodPost,
381 u: "https://gitlab.com/api/v4/markdown",
382 body: `{"text":"hello"}`,
383 headers: "Content-Type: application/json; charset=utf-8\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
384 },
385 },
386 {
387 name: "an explicit content type beats the raw-body default",
388 args: args{
389 host: "gitlab.com",
390 method: http.MethodPost,
391 p: "markdown",
392 params: strings.NewReader("hello"),
393 headers: []string{"Content-Type: text/plain"},
394 rawBodyIsJSON: true,
395 },
396 wantErr: false,
397 want: expects{
398 method: http.MethodPost,
399 u: "https://gitlab.com/api/v4/markdown",
400 body: "hello",
401 headers: "Content-Type: text/plain\r\nPrivate-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
402 },
403 },
404 {
405 name: "a raw body not announced as JSON is left undeclared",
406 args: args{
407 host: "gitlab.com",
408 method: http.MethodPost,
409 p: "markdown",
410 params: strings.NewReader("hello"),
411 headers: []string{},
412 rawBodyIsJSON: false,
413 },
414 wantErr: false,
415 want: expects{
416 method: http.MethodPost,
417 u: "https://gitlab.com/api/v4/markdown",
418 body: "hello",
419 headers: "Private-Token: OTOKEN\r\nUser-Agent: glab test client\r\n",
420 },
421 },
422 }
423 for _, tt := range tests {
424 var options []api.ClientOption
425 httpClient := cmdtest.NewTestApiClient(t, client, "OTOKEN", tt.args.host, options...)
426 t.Run(tt.name, func(t *testing.T) {
427 got, err := httpRequest(t.Context(), httpClient, tt.args.method, tt.args.p, tt.args.params, tt.args.headers, tt.args.rawBodyIsJSON)
428 if (err != nil) != tt.wantErr {
429 t.Errorf("httpRequest() error = %v, wantErr %v", err, tt.wantErr)
430 return
431 }
432 if !assert.NotNil(t, got) {
433 return
434 }
435 defer got.Body.Close()
436 req := got.Request
437 if req.Method != tt.want.method {
438 t.Errorf("Request.Method = %q, want %q", req.Method, tt.want.method)
439 }
440 if req.URL.String() != tt.want.u {
441 t.Errorf("Request.URL = %q, want %q", req.URL.String(), tt.want.u)
442 }
443 if tt.want.body != "" {
444 bb, err := io.ReadAll(req.Body)
445 if err != nil {
446 t.Errorf("Request.Body ReadAll error = %v", err)
447 return
448 }
449 if string(bb) != tt.want.body {
450 t.Errorf("Request.Body = %q, want %q", string(bb), tt.want.body)
451 }
452 }
454 h := bytes.Buffer{}
455 err = req.Header.WriteSubset(&h, map[string]bool{})
456 if err != nil {
457 t.Errorf("Request.Header WriteSubset error = %v", err)
458 return
459 }
460 if h.String() != tt.want.headers {
461 t.Errorf("Request.Header = %q, want %q", h.String(), tt.want.headers)
462 }
463 })
464 }
467func Test_httpRequest_invalidURLReturnsError(t *testing.T) {
468 test.ClearEnvironmentVariables(t)
470 client := &http.Client{}
471 client.Transport = roundTripFunc(func(req *http.Request) (*http.Response, error) {
472 return nil, fmt.Errorf("HTTP request made with invalid URL")
473 })
475 httpClient := cmdtest.NewTestApiClient(t, client, "OTOKEN", "gitlab.com")
476 _, err := httpRequest(t.Context(), httpClient, http.MethodGet, "http://host:abc", nil, nil, false) //nolint:bodyclose // transport returns nil response on invalid-URL error path
477 require.Error(t, err)
478 require.Contains(t, err.Error(), "invalid request URL")
481func Test_addQuery(t *testing.T) {
482 type args struct {
483 path string
484 params map[string]any
485 }
486 tests := []struct {
487 name string
488 args args
489 want string
490 }{
491 {
492 name: "string",
493 args: args{
494 path: "",
495 params: map[string]any{"a": "hello"},
496 },
497 want: "?a=hello",
498 },
499 {
500 name: "append",
501 args: args{
502 path: "path",
503 params: map[string]any{"a": "b"},
504 },
505 want: "path?a=b",
506 },
507 {
508 name: "append query",
509 args: args{
510 path: "path?foo=bar",
511 params: map[string]any{"a": "b"},
512 },
513 want: "path?foo=bar&a=b",
514 },
515 {
516 name: "[]byte",
517 args: args{
518 path: "",
519 params: map[string]any{"a": []byte("hello")},
520 },
521 want: "?a=hello",
522 },
523 {
524 name: "int",
525 args: args{
526 path: "",
527 params: map[string]any{"a": 123},
528 },
529 want: "?a=123",
530 },
531 {
532 name: "nil",
533 args: args{
534 path: "",
535 params: map[string]any{"a": nil},
536 },
537 want: "?a=",
538 },
539 {
540 name: "bool",
541 args: args{
542 path: "",
543 params: map[string]any{"a": true, "b": false},
544 },
545 want: "?a=true&b=false",
546 },
547 {
548 name: "JSON array as repeated key[]",
549 args: args{
550 path: "",
551 params: map[string]any{"topics": []any{"ruby", "rails"}},
552 },
553 want: "?topics%5B%5D=ruby&topics%5B%5D=rails",
554 },
555 {
556 name: "JSON numeric array renders integers cleanly",
557 args: args{
558 path: "",
559 params: map[string]any{"iids": []any{json.Number("1"), json.Number("2")}},
560 },
561 want: "?iids%5B%5D=1&iids%5B%5D=2",
562 },
563 {
564 // An empty array contributes no parameters, so the path must come back
565 // untouched rather than carrying a bare separator.
566 name: "empty JSON array adds no parameter and no separator",
567 args: args{
568 path: "projects",
569 params: map[string]any{"topics": []any{}},
570 },
571 want: "projects",
572 },
573 {
574 name: "empty JSON array does not displace other parameters",
575 args: args{
576 path: "projects",
577 params: map[string]any{"topics": []any{}, "search": "glab"},
578 },
579 want: "projects?search=glab",
580 },
581 {
582 name: "booleans inside an array render as true and false",
583 args: args{
584 path: "",
585 params: map[string]any{"flags": []any{true, false}},
586 },
587 want: "?flags%5B%5D=true&flags%5B%5D=false",
588 },
589 {
590 // A second suffix would send ids[][]=, an array of arrays.
591 name: "repeated flag values keep the name they were given",
592 args: args{
593 path: "",
594 params: map[string]any{"ids[]": queryList{"1", "2"}},
595 },
596 want: "?ids%5B%5D=1&ids%5B%5D=2",
597 },
598 {
599 name: "repeated flag values render by type, not as array elements",
600 args: args{
601 path: "",
602 params: map[string]any{"ids[]": queryList{1, true, nil, []byte("file")}},
603 },
604 want: "?ids%5B%5D=1&ids%5B%5D=true&ids%5B%5D=&ids%5B%5D=file",
605 },
606 {
607 // A single flag holding a JSON array reaches this as a bare []any,
608 // so the suffix test belongs on both arms: appending here would send
609 // ids[][]= for a name the user already spelled with its brackets.
610 name: "JSON array under a name ending in [] keeps one bracket pair",
611 args: args{
612 path: "",
613 params: map[string]any{"ids[]": []any{json.Number("1"), json.Number("2")}},
614 },
615 want: "?ids%5B%5D=1&ids%5B%5D=2",
616 },
617 {
618 name: "JSON array under a nested name ending in [] keeps one pair",
619 args: args{
620 path: "",
621 params: map[string]any{"a[b][]": []any{json.Number("1")}},
622 },
623 want: "?a%5Bb%5D%5B%5D=1",
624 },
625 }
626 for _, tt := range tests {
627 t.Run(tt.name, func(t *testing.T) {
628 if got, err := parseQuery(tt.args.path, tt.args.params); got != tt.want {
629 if err != nil {
630 t.Error(err.Error())
631 }
632 t.Errorf("parseQuery() = %v, want %v", got, tt.want)
633 }
634 })
635 }
638func Test_parseQuery_nonScalar(t *testing.T) {
639 if _, err := parseQuery("", map[string]any{"config": map[string]any{"enabled": true}}); err == nil {
640 t.Error("expected error for object query parameter, got nil")
641 }
642 if _, err := parseQuery("", map[string]any{"nested": []any{[]any{"a"}}}); err == nil {
643 t.Error("expected error for nested array in query parameter, got nil")
644 }
645 // A query string has no representation for null. Encoding it as an empty
646 // value would silently turn null into "", so it is rejected instead.
647 if _, err := parseQuery("", map[string]any{"flags": []any{true, nil, false}}); err == nil {
648 t.Error("expected error for null array element in query parameter, got nil")
649 }
652func Test_buildMultipartBody(t *testing.T) {
653 t.Parallel()
655 t.Run("text fields only", func(t *testing.T) {
656 t.Parallel()
657 body, contentType := buildMultipartBody(
658 // Part names are never parsed, bracket or no bracket: --form is
659 // unaffected by the field-name rule the JSON body path enforces.
660 []string{"branch=main", "message=hello world", "position[base_sha]=abc"},
661 io.NopCloser(bytes.NewReader(nil)),
662 )
664 mediaType, params, err := mime.ParseMediaType(contentType)
665 require.NoError(t, err)
666 assert.Equal(t, "multipart/form-data", mediaType)
668 mr := multipart.NewReader(body, params["boundary"])
670 part, err := mr.NextPart()
671 require.NoError(t, err)
672 assert.Equal(t, "branch", part.FormName())
673 val, _ := io.ReadAll(part)
674 assert.Equal(t, "main", string(val))
676 part, err = mr.NextPart()
677 require.NoError(t, err)
678 assert.Equal(t, "message", part.FormName())
679 val, _ = io.ReadAll(part)
680 assert.Equal(t, "hello world", string(val))
682 part, err = mr.NextPart()
683 require.NoError(t, err)
684 assert.Equal(t, "position[base_sha]", part.FormName())
685 val, _ = io.ReadAll(part)
686 assert.Equal(t, "abc", string(val))
687 })
689 t.Run("file field via @filepath", func(t *testing.T) {
690 t.Parallel()
691 tmp := t.TempDir()
692 f := filepath.Join(tmp, "upload.txt")
693 require.NoError(t, os.WriteFile(f, []byte("file content"), 0o600))
695 body, contentType := buildMultipartBody(
696 []string{"file=@" + f, "branch=main"},
697 io.NopCloser(bytes.NewReader(nil)),
698 )
700 mediaType, params, err := mime.ParseMediaType(contentType)
701 require.NoError(t, err)
702 assert.Equal(t, "multipart/form-data", mediaType)
704 mr := multipart.NewReader(body, params["boundary"])
706 // first part: the file
707 part, err := mr.NextPart()
708 require.NoError(t, err)
709 assert.Equal(t, "file", part.FormName())
710 assert.Equal(t, "upload.txt", part.FileName())
711 val, _ := io.ReadAll(part)
712 assert.Equal(t, "file content", string(val))
714 // second part: text field
715 part, err = mr.NextPart()
716 require.NoError(t, err)
717 assert.Equal(t, "branch", part.FormName())
718 val, _ = io.ReadAll(part)
719 assert.Equal(t, "main", string(val))
720 })
722 t.Run("file field via stdin (@-)", func(t *testing.T) {
723 t.Parallel()
724 stdin := io.NopCloser(bytes.NewBufferString("stdin content"))
725 body, contentType := buildMultipartBody(
726 []string{"file=@-"},
727 stdin,
728 )
730 _, params, err := mime.ParseMediaType(contentType)
731 require.NoError(t, err)
733 mr := multipart.NewReader(body, params["boundary"])
734 part, err := mr.NextPart()
735 require.NoError(t, err)
736 assert.Equal(t, "file", part.FormName())
737 val, _ := io.ReadAll(part)
738 assert.Equal(t, "stdin content", string(val))
739 })
741 t.Run("missing file returns error", func(t *testing.T) {
742 t.Parallel()
743 // Errors propagate through the pipe reader, not at construction time.
744 body, _ := buildMultipartBody(
745 []string{"file=@/nonexistent/path/file.bin"},
746 io.NopCloser(bytes.NewReader(nil)),
747 )
748 _, readErr := io.ReadAll(body)
749 require.Error(t, readErr)
750 })
752 t.Run("malformed field returns error", func(t *testing.T) {
753 t.Parallel()
754 // Errors propagate through the pipe reader, not at construction time.
755 body, _ := buildMultipartBody(
756 []string{"no-equals-sign"},
757 io.NopCloser(bytes.NewReader(nil)),
758 )
759 _, readErr := io.ReadAll(body)
760 require.Error(t, readErr)
761 })
Diagnostics7 git calls · 36 ms
CallStatusSizeTime036 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB9 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=59849
git.response.cache=UPDATING
git.response.duration_ms=9
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
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=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:02001.8 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=1857
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=dce174ff8c632a19d17eea99c8a9b7c37fb2b592
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1857
git.pkt.payload.max=1830
git.sideband.band1.bytes=1830
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1830
git.pack.trailer=fb03183b7909876778f740d196d7516811003517
Open pack map
fetchtree:0200285 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=285
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=48bbcb7832066dead74ecdecb6257183f3d03bf0
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=285
git.pkt.payload.max=258
git.sideband.band1.bytes=258
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=258
git.pack.trailer=2570819fa1caef7b0fd3f7ba2d1b1a658b78702e
Open pack map
fetch2004.2 KiB · hit18 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=18
git.response.bytes=4296
git.response.cache=HIT
git.response.duration_ms=18
git.fetch.wants=66dbafa94ef770307bb305765a46c97d586dbb2f
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=4296
git.pkt.payload.max=4269
git.sideband.band1.bytes=4269
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://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e22e9348f4a594
Request
9779c80a…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format