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/* This test attempts to use all form API features that are not
27 * used elsewhere.
28 */
30/* curl_formget callback to count characters. */
31static size_t count_chars(void *userp, const char *buf, size_t len)
32{
33 size_t *pcounter = (size_t *)userp;
35 (void)buf;
36 *pcounter += len;
37 return len;
38}
40static CURLcode test_lib650(const char *URL)
41{
42 CURL *curl = NULL;
43 CURLcode result = TEST_ERR_MAJOR_BAD;
44 CURLFORMcode formrc;
45 struct curl_slist *headers, *headers2 = NULL;
46 struct curl_httppost *formpost = NULL;
47 struct curl_httppost *lastptr = NULL;
48 struct curl_forms formarray[3];
49 size_t formlength = 0;
50 char flbuf[32];
52 static const char testname[] = "fieldname";
53 static char testdata[] = "this is what we post to the silly web server";
55 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
56 curl_mfprintf(stderr, "curl_global_init() failed\n");
57 return TEST_ERR_MAJOR_BAD;
58 }
60 /* Check proper name and data copying, as well as headers. */
61 headers = curl_slist_append(NULL, "X-customheader-1: Header 1 data");
62 if(!headers) {
63 goto test_cleanup;
64 }
65 headers2 = curl_slist_append(headers, "X-customheader-2: Header 2 data");
66 if(!headers2) {
67 goto test_cleanup;
68 }
69 headers = headers2;
70 headers2 = curl_slist_append(headers, "Content-Type: text/plain");
71 if(!headers2) {
72 goto test_cleanup;
73 }
74 headers = headers2;
75 formrc = curl_formadd(&formpost, &lastptr,
76 CURLFORM_COPYNAME, testname,
77 CURLFORM_COPYCONTENTS, testdata,
78 CURLFORM_CONTENTHEADER, headers,
79 CURLFORM_END);
80 if(formrc) {
81 curl_mprintf("curl_formadd(1) = %d\n", (int)formrc);
82 goto test_cleanup;
83 }
85 /* Use a form array for the non-copy test. */
86 formarray[0].option = CURLFORM_PTRCONTENTS;
87 formarray[0].value = testdata;
88 formarray[1].option = CURLFORM_CONTENTSLENGTH;
89 formarray[1].value = (char *)(strlen(testdata) - 1);
90 formarray[2].option = CURLFORM_END;
91 formarray[2].value = NULL;
92 formrc = curl_formadd(&formpost,
93 &lastptr,
94 CURLFORM_PTRNAME, testname,
95 CURLFORM_NAMELENGTH, (long)CURL_CSTRLEN(testname) - 1,
96 CURLFORM_ARRAY, formarray,
97 CURLFORM_FILENAME, "remotefile.txt",
98 CURLFORM_END);
100 if(formrc) {
101 curl_mprintf("curl_formadd(2) = %d\n", (int)formrc);
102 goto test_cleanup;
103 }
105 /* Now change in-memory data to affect CURLOPT_PTRCONTENTS value.
106 Copied values (first field) must not be affected.
107 CURLOPT_PTRNAME actually copies the name thus we do not test this here. */
108 testdata[0]++;
110 /* Check multi-files and content type propagation. */
111 formrc = curl_formadd(&formpost,
112 &lastptr,
113 CURLFORM_COPYNAME, "multifile",
114 CURLFORM_FILE, libtest_arg2, /* Set in first.c. */
115 CURLFORM_FILE, libtest_arg2,
116 CURLFORM_CONTENTTYPE, "text/whatever",
117 CURLFORM_FILE, libtest_arg2,
118 CURLFORM_END);
120 if(formrc) {
121 curl_mprintf("curl_formadd(3) = %d\n", (int)formrc);
122 goto test_cleanup;
123 }
125 /* Check data from file content. */
126 formrc = curl_formadd(&formpost,
127 &lastptr,
128 CURLFORM_COPYNAME, "filecontents",
129 CURLFORM_FILECONTENT, libtest_arg2,
130 CURLFORM_END);
131 if(formrc) {
132 curl_mprintf("curl_formadd(4) = %d\n", (int)formrc);
133 goto test_cleanup;
134 }
136 /* Measure the current form length.
137 * This is done before including stdin data because we want to reuse it
138 * and stdin cannot be rewound.
139 */
140 curl_formget(formpost, (void *)&formlength, count_chars);
142 /* Include length in data for external check. */
143 curl_msnprintf(flbuf, sizeof(flbuf), "%zu", formlength);
145 formrc = curl_formadd(&formpost,
146 &lastptr,
147 CURLFORM_COPYNAME, "formlength",
148 CURLFORM_COPYCONTENTS, flbuf,
149 CURLFORM_END);
151 if(formrc) {
152 curl_mprintf("curl_formadd(5) = %d\n", (int)formrc);
153 goto test_cleanup;
154 }
156 /* Check stdin (may be problematic on some platforms). */
157 formrc = curl_formadd(&formpost,
158 &lastptr,
159 CURLFORM_COPYNAME, "standardinput",
160 CURLFORM_FILE, "-",
161 CURLFORM_END);
163 if(formrc) {
164 curl_mprintf("curl_formadd(6) = %d\n", (int)formrc);
165 goto test_cleanup;
166 }
168 curl = curl_easy_init();
169 if(!curl) {
170 curl_mfprintf(stderr, "curl_easy_init() failed\n");
171 goto test_cleanup;
172 }
174 /* First set the URL that is about to receive our POST. */
175 easy_setopt(curl, CURLOPT_URL, URL);
177 /* send a multi-part formpost */
178 easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
180 /* get verbose debug output please */
181 easy_setopt(curl, CURLOPT_VERBOSE, 1L);
183 easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
184 easy_setopt(curl, CURLOPT_POSTREDIR, CURL_REDIR_POST_301);
186 /* include headers in the output */
187 easy_setopt(curl, CURLOPT_HEADER, 1L);
189 /* Perform the request, result gets the return code */
190 result = curl_easy_perform(curl);
192test_cleanup:
194 /* always cleanup */
195 curl_easy_cleanup(curl);
197 /* now cleanup the formpost chain */
198 curl_formfree(formpost);
199 curl_slist_free_all(headers);
201 curl_global_cleanup();
203 return result;
204}
Diagnostics4 git calls · 117 ms
CallStatusSizeTime0117 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 · 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.2 KiB111 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=111 git.response.bytes=2252 git.response.cache=MISS git.response.duration_ms=111 git.fetch.wants=04b288725fc4d529204d2e77e920d49eebf23102 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=2252 git.pkt.payload.max=2231 git.sideband.band1.bytes=2230 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
- a5e3142058e43e6e
- Request
- a3abb6b2…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format