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"
26struct t643_WriteThis {
27 const char *readptr;
28 curl_off_t sizeleft;
29};
31static size_t t643_read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
32{
33 struct t643_WriteThis *pooh = (struct t643_WriteThis *)userp;
34 int eof;
36 if(size * nmemb < 1)
37 return 0;
39 if(testnum == 643) {
40 eof = pooh->sizeleft <= 0;
41 if(!eof)
42 pooh->sizeleft--;
43 }
44 else {
45 eof = !*pooh->readptr;
46 }
48 if(!eof) {
49 *ptr = *pooh->readptr; /* copy one single byte */
50 pooh->readptr++; /* advance pointer */
51 return 1; /* we return 1 byte at a time! */
52 }
54 return 0; /* no more data left to deliver */
55}
57static CURLcode t643_test_once(const char *URL, bool oldstyle)
58{
59 static const char testdata[] = "dummy\n";
61 CURL *curl;
62 CURLcode result = CURLE_OK;
64 curl_mime *mime = NULL;
65 curl_mimepart *part = NULL;
66 struct t643_WriteThis pooh;
67 struct t643_WriteThis pooh2;
68 curl_off_t datasize = -1;
70 pooh.readptr = testdata;
71 if(testnum == 643)
72 datasize = (curl_off_t)CURL_CSTRLEN(testdata);
73 pooh.sizeleft = datasize;
75 curl = curl_easy_init();
76 if(!curl) {
77 curl_mfprintf(stderr, "curl_easy_init() failed\n");
78 curl_global_cleanup();
79 return TEST_ERR_MAJOR_BAD;
80 }
82 mime = curl_mime_init(curl);
83 if(!mime) {
84 curl_mfprintf(stderr, "curl_mime_init() failed\n");
85 curl_easy_cleanup(curl);
86 curl_global_cleanup();
87 return TEST_ERR_MAJOR_BAD;
88 }
90 part = curl_mime_addpart(mime);
91 if(!part) {
92 curl_mfprintf(stderr, "curl_mime_addpart(1) failed\n");
93 curl_mime_free(mime);
94 curl_easy_cleanup(curl);
95 curl_global_cleanup();
96 return TEST_ERR_MAJOR_BAD;
97 }
99 /* Fill in the file upload part */
100 if(oldstyle) {
101 result = curl_mime_name(part, "sendfile");
102 if(!result)
103 result = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL,
104 &pooh);
105 if(!result)
106 result = curl_mime_filename(part, "postit2.c");
107 }
108 else {
109 /* new style */
110 result = curl_mime_name(part, "sendfile alternative");
111 if(!result)
112 result = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL,
113 &pooh);
114 if(!result)
115 result = curl_mime_filename(part, "filename 2 ");
116 }
118 if(result)
119 curl_mprintf("curl_mime_xxx(1) = %s\n", curl_easy_strerror(result));
121 /* Now add the same data with another name and make it not look like
122 a file upload but still using the callback */
124 pooh2.readptr = testdata;
125 if(testnum == 643)
126 datasize = (curl_off_t)CURL_CSTRLEN(testdata);
127 pooh2.sizeleft = datasize;
129 part = curl_mime_addpart(mime);
130 if(!part) {
131 curl_mfprintf(stderr, "curl_mime_addpart(2) failed\n");
132 curl_mime_free(mime);
133 curl_easy_cleanup(curl);
134 curl_global_cleanup();
135 return TEST_ERR_MAJOR_BAD;
136 }
137 /* Fill in the file upload part */
138 result = curl_mime_name(part, "callbackdata");
139 if(!result)
140 result = curl_mime_data_cb(part, datasize, t643_read_cb, NULL, NULL,
141 &pooh2);
143 if(result)
144 curl_mprintf("curl_mime_xxx(2) = %s\n", curl_easy_strerror(result));
146 part = curl_mime_addpart(mime);
147 if(!part) {
148 curl_mfprintf(stderr, "curl_mime_addpart(3) failed\n");
149 curl_mime_free(mime);
150 curl_easy_cleanup(curl);
151 curl_global_cleanup();
152 return TEST_ERR_MAJOR_BAD;
153 }
155 /* Fill in the filename field */
156 result = curl_mime_name(part, "filename");
157 if(!result)
158 result = curl_mime_data(part, "postit2.c", CURL_ZERO_TERMINATED);
160 if(result)
161 curl_mprintf("curl_mime_xxx(3) = %s\n", curl_easy_strerror(result));
163 /* Fill in a submit field too */
164 part = curl_mime_addpart(mime);
165 if(!part) {
166 curl_mfprintf(stderr, "curl_mime_addpart(4) failed\n");
167 curl_mime_free(mime);
168 curl_easy_cleanup(curl);
169 curl_global_cleanup();
170 return TEST_ERR_MAJOR_BAD;
171 }
172 result = curl_mime_name(part, "submit");
173 if(!result)
174 result = curl_mime_data(part, "send", CURL_ZERO_TERMINATED);
176 if(result)
177 curl_mprintf("curl_mime_xxx(4) = %s\n", curl_easy_strerror(result));
179 part = curl_mime_addpart(mime);
180 if(!part) {
181 curl_mfprintf(stderr, "curl_mime_addpart(5) failed\n");
182 curl_mime_free(mime);
183 curl_easy_cleanup(curl);
184 curl_global_cleanup();
185 return TEST_ERR_MAJOR_BAD;
186 }
187 result = curl_mime_name(part, "somename");
188 if(!result)
189 result = curl_mime_filename(part, "somefile.txt");
190 if(!result)
191 result = curl_mime_data(part, "blah blah", 9);
193 if(result)
194 curl_mprintf("curl_mime_xxx(5) = %s\n", curl_easy_strerror(result));
196 /* First set the URL that is about to receive our POST. */
197 easy_setopt(curl, CURLOPT_URL, URL);
199 /* send a multi-part mimepost */
200 easy_setopt(curl, CURLOPT_MIMEPOST, mime);
202 /* get verbose debug output please */
203 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
205 /* include headers in the output */
206 easy_setopt(curl, CURLOPT_HEADER, 1L);
208 /* Perform the request, result gets the return code */
209 result = curl_easy_perform(curl);
211test_cleanup:
213 /* always cleanup */
214 curl_easy_cleanup(curl);
216 /* now cleanup the mimepost structure */
217 curl_mime_free(mime);
219 return result;
220}
222static CURLcode t643_cyclic_add(void)
223{
224 CURL *curl = curl_easy_init();
225 curl_mime *mime = curl_mime_init(curl);
226 curl_mimepart *part = curl_mime_addpart(mime);
227 CURLcode result = curl_mime_subparts(part, mime);
229 if(result == CURLE_BAD_FUNCTION_ARGUMENT) {
230 curl_mime *submime = curl_mime_init(curl);
231 curl_mimepart *subpart = curl_mime_addpart(submime);
233 curl_mime_subparts(part, submime);
234 result = curl_mime_subparts(subpart, mime);
235 }
237 curl_mime_free(mime);
238 curl_easy_cleanup(curl);
239 if(result != CURLE_BAD_FUNCTION_ARGUMENT)
240 /* that should have failed */
241 return TEST_ERR_FAILURE;
243 return CURLE_OK;
244}
246static CURLcode test_lib643(const char *URL)
247{
248 CURLcode result;
250 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
251 curl_mfprintf(stderr, "curl_global_init() failed\n");
252 return TEST_ERR_MAJOR_BAD;
253 }
255 result = t643_test_once(URL, TRUE); /* old */
256 if(!result)
257 result = t643_test_once(URL, FALSE); /* new */
259 if(!result)
260 result = t643_cyclic_add();
262 curl_global_cleanup();
264 return result;
265}
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B2 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 · 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=25 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.1 KiB · hit25 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=2135 git.response.cache=HIT git.response.duration_ms=25 git.fetch.wants=c2aed4f0d29c0251db2d64b62a9c1882d18ae255 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=2135 git.pkt.payload.max=2114 git.sideband.band1.bytes=2113 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
- a5e306efa97415db
- Request
- 10f21009…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format