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"
28#ifndef CURL_DISABLE_WEBSOCKETS
30static const char *descr_flags(int flags)
31{
32 if(flags & CURLWS_TEXT)
33 return flags & CURLWS_CONT ? "txt ---" : "txt fin";
34 if(flags & CURLWS_BINARY)
35 return flags & CURLWS_CONT ? "bin ---" : "bin fin";
36 if(flags & CURLWS_PING)
37 return "ping";
38 if(flags & CURLWS_PONG)
39 return "pong";
40 if(flags & CURLWS_CLOSE)
41 return "close";
42 DEBUGASSERT(FALSE);
43 return "";
44}
46static CURLcode send_header(CURL *curl, int flags, size_t size)
47{
48 CURLcode result = CURLE_OK;
49 size_t nsent;
51retry:
52 result = curl_ws_send(curl, NULL, 0, &nsent, (curl_off_t)size,
53 flags | CURLWS_OFFSET);
54 if(result == CURLE_AGAIN) {
55 DEBUGASSERT(nsent == 0);
56 goto retry;
57 }
58 if(result) {
59 curl_mfprintf(stderr, "%s:%d curl_ws_send() failed with code %d (%s)\n",
60 __FILE__, __LINE__, (int)result, curl_easy_strerror(result));
61 DEBUGASSERT(nsent == 0);
62 return result;
63 }
65 DEBUGASSERT(nsent == 0);
67 return CURLE_OK;
68}
70static CURLcode recv_header(CURL *curl, int *flags, curl_off_t *offset,
71 curl_off_t *bytesleft)
72{
73 CURLcode result = CURLE_OK;
74 size_t nread;
75 const struct curl_ws_frame *meta;
77 *flags = 0;
78 *offset = 0;
79 *bytesleft = 0;
81retry:
82 result = curl_ws_recv(curl, NULL, 0, &nread, &meta);
83 if(result == CURLE_AGAIN) {
84 DEBUGASSERT(nread == 0);
85 goto retry;
86 }
87 if(result) {
88 curl_mfprintf(stderr, "%s:%d curl_ws_recv() failed with code %d (%s)\n",
89 __FILE__, __LINE__, (int)result, curl_easy_strerror(result));
90 DEBUGASSERT(nread == 0);
91 return result;
92 }
94 DEBUGASSERT(nread == 0);
95 DEBUGASSERT(meta);
96 DEBUGASSERT(meta->flags);
97 DEBUGASSERT(meta->offset == 0);
99 *flags = meta->flags;
100 *offset = meta->offset;
101 *bytesleft = meta->bytesleft;
103 curl_mfprintf(stdout, "%s [%" FMT_OFF_T "]", descr_flags(meta->flags),
104 meta->bytesleft);
106 if(meta->bytesleft > 0)
107 curl_mfprintf(stdout, " ");
109 result = send_header(curl, meta->flags, (size_t)meta->bytesleft);
110 if(result)
111 return result;
113 return CURLE_OK;
114}
116static CURLcode send_chunk(CURL *curl, int flags, const char *buffer,
117 size_t size, size_t *offset)
118{
119 CURLcode result = CURLE_OK;
120 size_t nsent;
122retry:
123 result = curl_ws_send(curl, buffer + *offset, size - *offset, &nsent,
124 0, flags);
125 if(result == CURLE_AGAIN) {
126 DEBUGASSERT(nsent == 0);
127 goto retry;
128 }
129 if(result) {
130 curl_mfprintf(stderr, "%s:%d curl_ws_send() failed with code %d (%s)\n",
131 __FILE__, __LINE__, (int)result, curl_easy_strerror(result));
132 DEBUGASSERT(nsent == 0);
133 return result;
134 }
136 DEBUGASSERT(nsent <= size - *offset);
138 *offset += nsent;
140 return CURLE_OK;
141}
143static CURLcode recv_chunk(CURL *curl, int flags, curl_off_t *offset,
144 curl_off_t *bytesleft)
145{
146 CURLcode result = CURLE_OK;
147 char buffer[256];
148 size_t nread;
149 const struct curl_ws_frame *meta;
150 size_t sendoffset = 0;
152retry:
153 result = curl_ws_recv(curl, buffer, sizeof(buffer), &nread, &meta);
154 if(result == CURLE_AGAIN) {
155 DEBUGASSERT(nread == 0);
156 goto retry;
157 }
158 if(result) {
159 curl_mfprintf(stderr, "%s:%d curl_ws_recv() failed with code %d (%s)\n",
160 __FILE__, __LINE__, (int)result, curl_easy_strerror(result));
161 DEBUGASSERT(nread == 0);
162 return result;
163 }
165 DEBUGASSERT(nread <= sizeof(buffer));
166 DEBUGASSERT(meta);
167 DEBUGASSERT(meta->flags == flags);
168 DEBUGASSERT(meta->offset == *offset);
169 DEBUGASSERT(meta->bytesleft == (*bytesleft - (curl_off_t)nread));
171 *offset += nread;
172 *bytesleft -= nread;
174 fwrite(buffer, 1, nread, stdout);
176 while(sendoffset < nread) {
177 result = send_chunk(curl, flags, buffer, nread, &sendoffset);
178 if(result)
179 return result;
180 }
182 return CURLE_OK;
183}
185static CURLcode recv_frame(CURL *curl, bool *stop)
186{
187 CURLcode result = CURLE_OK;
188 int flags = 0;
189 curl_off_t offset = 0;
190 curl_off_t bytesleft = 0;
192 result = recv_header(curl, &flags, &offset, &bytesleft);
193 if(result)
194 return result;
196 while(bytesleft > 0) {
197 result = recv_chunk(curl, flags, &offset, &bytesleft);
198 if(result)
199 return result;
200 }
202 if(flags & CURLWS_CLOSE)
203 *stop = TRUE;
205 curl_mfprintf(stdout, "\n");
207 return result;
208}
209#endif
211static CURLcode test_lib2700(const char *URL)
212{
213#ifndef CURL_DISABLE_WEBSOCKETS
214 CURLcode result = CURLE_OK;
215 bool stop = FALSE;
216 CURL *curl;
218 global_init(CURL_GLOBAL_ALL);
219 curl_global_trace("ws");
220 easy_init(curl);
222 easy_setopt(curl, CURLOPT_URL, URL);
223 easy_setopt(curl, CURLOPT_USERAGENT, "client/test2700");
224 debug_config.nohex = TRUE;
225 debug_config.tracetime = TRUE;
226 easy_setopt(curl, CURLOPT_DEBUGDATA, &debug_config);
227 easy_setopt(curl, CURLOPT_DEBUGFUNCTION, libtest_debug_cb);
228 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
229 easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L);
230 if(testnum != 2708)
231 easy_setopt(curl, CURLOPT_WS_OPTIONS, CURLWS_NOAUTOPONG);
233 result = curl_easy_perform(curl);
234 if(result) {
235 curl_mfprintf(stderr,
236 "%s:%d curl_easy_perform() failed with code %d (%s)\n",
237 __FILE__, __LINE__, (int)result, curl_easy_strerror(result));
238 goto test_cleanup;
239 }
241 while(!stop) {
242 result = recv_frame(curl, &stop);
243 if(result)
244 goto test_cleanup;
245 }
247test_cleanup:
248 curl_easy_cleanup(curl);
249 curl_global_cleanup();
250 return result;
251#else
252 (void)URL;
253 curl_mfprintf(stderr, "Missing support\n");
254 return CURLE_UNSUPPORTED_PROTOCOL;
255#endif
256}
Diagnostics4 git calls · 159 ms
CallStatusSizeTime0159 ms
discover200152 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=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.0 KiB153 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=153 git.response.bytes=2013 git.response.cache=MISS git.response.duration_ms=153 git.fetch.wants=6d5a7ffc08065e7bc0839572113b5583a5a910a2 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=2013 git.pkt.payload.max=1992 git.sideband.band1.bytes=1991 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
- a5e35b713f05dfff
- Request
- 7916d4a7…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format