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"
28static int tse_found_tls_session = FALSE;
30static size_t write_tse_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
31{
32 CURL *curl = opaque;
33 (void)ptr;
34 if(!tse_found_tls_session) {
35 struct curl_tlssessioninfo *tlssession;
36 CURLcode result;
38 result = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tlssession);
39 if(result) {
40 curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
41 "failed: %s\n", curl_easy_strerror(result));
42 return result;
43 }
44 if(tlssession->backend == CURLSSLBACKEND_NONE) {
45 curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
46 "gave no backend\n");
47 return CURLE_FAILED_INIT;
48 }
49 if(!tlssession->internals) {
50 curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
51 "missing\n");
52 return CURLE_FAILED_INIT;
53 }
54 tse_found_tls_session = TRUE;
55 }
56 return size * nmemb;
57}
59static CURL *tse_add_transfer(CURLM *multi, CURLSH *share,
60 struct curl_slist *resolve,
61 const char *url, long http_version)
62{
63 CURL *curl;
64 CURLMcode mresult;
66 curl = curl_easy_init();
67 if(!curl) {
68 curl_mfprintf(stderr, "curl_easy_init failed\n");
69 return NULL;
70 }
71 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
72 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, cli_debug_cb);
73 curl_easy_setopt(curl, CURLOPT_URL, url);
74 curl_easy_setopt(curl, CURLOPT_SHARE, share);
75 curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
76 curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1L);
77 curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
78 curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, http_version);
79 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_tse_cb);
80 curl_easy_setopt(curl, CURLOPT_WRITEDATA, curl);
81 curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
82 curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
83 if(resolve)
84 curl_easy_setopt(curl, CURLOPT_RESOLVE, resolve);
86 mresult = curl_multi_add_handle(multi, curl);
87 if(mresult != CURLM_OK) {
88 curl_mfprintf(stderr, "curl_multi_add_handle: %s\n",
89 curl_multi_strerror(mresult));
90 curl_easy_cleanup(curl);
91 return NULL;
92 }
93 return curl;
94}
96static CURLcode test_cli_tls_session_reuse(const char *URL)
97{
98 CURLM *multi = NULL;
99 CURLMcode mresult;
100 int running_handles = 0, numfds;
101 CURLMsg *msg;
102 CURLSH *share = NULL;
103 CURLU *cu;
104 struct curl_slist *resolve = NULL;
105 char resolve_buf[1024];
106 int msgs_in_queue;
107 int add_more, waits, ongoing = 0;
108 char *host = NULL, *port = NULL;
109 long http_version = CURL_HTTP_VERSION_1_1;
110 CURLcode result = (CURLcode)1;
112 if(!URL || !libtest_arg2) {
113 curl_mfprintf(stderr, "need args: URL proto\n");
114 return (CURLcode)2;
115 }
117 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
118 curl_mfprintf(stderr, "curl_global_init() failed\n");
119 return (CURLcode)3;
120 }
122 if(!strcmp("h2", libtest_arg2))
123 http_version = CURL_HTTP_VERSION_2;
124 else if(!strcmp("h3", libtest_arg2))
125 http_version = CURL_HTTP_VERSION_3ONLY;
127 cu = curl_url();
128 if(!cu) {
129 curl_mfprintf(stderr, "out of memory\n");
130 result = (CURLcode)1;
131 goto cleanup;
132 }
133 if(curl_url_set(cu, CURLUPART_URL, URL, 0)) {
134 curl_mfprintf(stderr, "not a URL: '%s'\n", URL);
135 goto cleanup;
136 }
137 if(curl_url_get(cu, CURLUPART_HOST, &host, 0)) {
138 curl_mfprintf(stderr, "could not get host of '%s'\n", URL);
139 goto cleanup;
140 }
141 if(curl_url_get(cu, CURLUPART_PORT, &port, 0)) {
142 curl_mfprintf(stderr, "could not get port of '%s'\n", URL);
143 goto cleanup;
144 }
146 curl_msnprintf(resolve_buf, sizeof(resolve_buf) - 1, "%s:%s:127.0.0.1",
147 host, port);
148 resolve = curl_slist_append(resolve, resolve_buf);
150 multi = curl_multi_init();
151 if(!multi) {
152 curl_mfprintf(stderr, "curl_multi_init failed\n");
153 goto cleanup;
154 }
156 share = curl_share_init();
157 if(!share) {
158 curl_mfprintf(stderr, "curl_share_init failed\n");
159 goto cleanup;
160 }
161 curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
163 if(!tse_add_transfer(multi, share, resolve, URL, http_version))
164 goto cleanup;
165 ++ongoing;
166 add_more = 6;
167 waits = 3;
168 do {
169 mresult = curl_multi_perform(multi, &running_handles);
170 if(mresult != CURLM_OK) {
171 curl_mfprintf(stderr, "curl_multi_perform: %s\n",
172 curl_multi_strerror(mresult));
173 goto cleanup;
174 }
176 if(running_handles) {
177 mresult = curl_multi_poll(multi, NULL, 0, 1000000, &numfds);
178 if(mresult != CURLM_OK) {
179 curl_mfprintf(stderr, "curl_multi_poll: %s\n",
180 curl_multi_strerror(mresult));
181 goto cleanup;
182 }
183 }
185 if(waits) {
186 --waits;
187 }
188 else {
189 while(add_more) {
190 if(!tse_add_transfer(multi, share, resolve, URL, http_version))
191 goto cleanup;
192 ++ongoing;
193 --add_more;
194 }
195 }
197 /* Check for finished handles and remove. */
198 /* !checksrc! disable EQUALSNULL 1 */
199 while((msg = curl_multi_info_read(multi, &msgs_in_queue)) != NULL) {
200 if(msg->msg == CURLMSG_DONE) {
201 long status = 0;
202 curl_off_t xfer_id;
203 curl_easy_getinfo(msg->easy_handle, CURLINFO_XFER_ID, &xfer_id);
204 curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &status);
205 if(msg->data.result == CURLE_SEND_ERROR ||
206 msg->data.result == CURLE_RECV_ERROR) {
207 /* We get these if the server had a GOAWAY in transit on
208 * reusing a connection */
209 }
210 else if(msg->data.result) {
211 curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
212 ": failed with %d\n", xfer_id, (int)msg->data.result);
213 goto cleanup;
214 }
215 else if(status != 200) {
216 curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T
217 ": wrong http status %ld (expected 200)\n", xfer_id,
218 status);
219 goto cleanup;
220 }
221 curl_multi_remove_handle(multi, msg->easy_handle);
222 curl_easy_cleanup(msg->easy_handle);
223 --ongoing;
224 curl_mfprintf(stderr, "transfer #%" CURL_FORMAT_CURL_OFF_T " retiring "
225 "(%d now running)\n", xfer_id, running_handles);
226 }
227 }
229 curl_mfprintf(stderr, "running_handles=%d, yet_to_start=%d\n",
230 running_handles, add_more);
232 } while(ongoing || add_more);
234 if(!tse_found_tls_session) {
235 curl_mfprintf(stderr, "CURLINFO_TLS_SSL_PTR not found during run\n");
236 result = CURLE_FAILED_INIT;
237 goto cleanup;
238 }
240 curl_mfprintf(stderr, "exiting\n");
241 result = CURLE_OK;
243cleanup:
245 if(multi) {
246 CURL **list = curl_multi_get_handles(multi);
247 if(list) {
248 int i;
249 for(i = 0; list[i]; i++) {
250 curl_multi_remove_handle(multi, list[i]);
251 curl_easy_cleanup(list[i]);
252 }
253 curl_free(list);
254 }
255 curl_multi_cleanup(multi);
256 }
257 curl_share_cleanup(share);
258 curl_slist_free_all(resolve);
259 curl_free(host);
260 curl_free(port);
261 if(cu)
262 curl_url_cleanup(cu);
263 curl_global_cleanup();
265 return result;
266}
Diagnostics4 git calls · 496 ms
CallStatusSizeTime0496 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=2 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.6 KiB491 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=491 git.response.bytes=2694 git.response.cache=MISS git.response.duration_ms=491 git.fetch.wants=ba97485a96c243120a8195f6a160374fced7a8ba 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=2694 git.pkt.payload.max=2673 git.sideband.band1.bytes=2672 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
- a5e2fb217ba090c0
- Request
- d4996f49…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format