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/* <DESC>
25 * Issue an HTTP POST and provide the data through the read callback.
26 * </DESC>
27 */
28#include <stdio.h>
29#include <string.h>
31#include <curl/curl.h>
33/* silly test data to POST */
34static const char data[] =
35 "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
36 "Sed vel urna neque. Ut quis leo metus. Quisque eleifend, ex at "
37 "laoreet rhoncus, odio ipsum semper metus, at tempus ante urna in mauris. "
38 "Suspendisse ornare tempor venenatis. Ut dui neque, pellentesque a ______ "
39 "eget, mattis vitae ligula. Fusce ut pharetra est. Ut ullamcorper mi ac "
40 "sollicitudin semper. Praesent sit amet tellus ______, posuere nulla non, "
41 "rhoncus ipsum.";
43struct WriteThis {
44 const char *readptr;
45 size_t sizeleft;
46};
48static size_t read_cb(char *dest, size_t size, size_t nmemb, void *userp)
49{
50 struct WriteThis *wt = (struct WriteThis *)userp;
51 size_t buffer_size = size * nmemb;
53 if(wt->sizeleft) {
54 /* copy as much as possible from the source to the destination */
55 size_t copy_this_much = wt->sizeleft;
56 if(copy_this_much > buffer_size)
57 copy_this_much = buffer_size;
58 memcpy(dest, wt->readptr, copy_this_much);
60 wt->readptr += copy_this_much;
61 wt->sizeleft -= copy_this_much;
62 return copy_this_much; /* we copied this many bytes */
63 }
65 return 0; /* no more data left to deliver */
66}
68int main(void)
69{
70 CURL *curl;
71 CURLcode result;
73 struct WriteThis wt;
75 wt.readptr = data;
76 wt.sizeleft = strlen(data);
78 /* In Windows, this inits the Winsock stuff */
79 result = curl_global_init(CURL_GLOBAL_ALL);
80 /* Check for errors */
81 if(result != CURLE_OK) {
82 fprintf(stderr, "curl_global_init() failed: %s\n",
83 curl_easy_strerror(result));
84 return (int)result;
85 }
87 /* get a curl handle */
88 curl = curl_easy_init();
89 if(curl) {
90 /* First set the URL that is about to receive our POST. */
91 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/index.cgi");
93 /* Now specify we want to POST data */
94 curl_easy_setopt(curl, CURLOPT_POST, 1L);
96 /* we want to use our own read function */
97 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
99 /* pointer to pass to our read function */
100 curl_easy_setopt(curl, CURLOPT_READDATA, &wt);
102 /* get verbose debug output please */
103 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
105 /* If you use POST to an HTTP 1.1 server, you can send data without knowing
106 the size before starting the POST if you use chunked encoding. You
107 enable this by adding a header like "Transfer-Encoding: chunked" with
108 CURLOPT_HTTPHEADER. With HTTP 1.0 or without chunked transfer, you must
109 specify the size in the request. */
110#ifdef USE_CHUNKED
111 {
112 struct curl_slist *chunk = NULL;
114 chunk = curl_slist_append(chunk, "Transfer-Encoding: chunked");
115 result = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
116 /* use curl_slist_free_all() after the *perform() call to free this
117 list again */
118 }
119#else
120 /* Set the expected POST size. If you want to POST large amounts of data,
121 consider CURLOPT_POSTFIELDSIZE_LARGE */
122 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)wt.sizeleft);
123#endif
125#ifdef DISABLE_EXPECT
126 /*
127 Using POST with HTTP 1.1 implies the use of a "Expect: 100-continue"
128 header. You can disable this header with CURLOPT_HTTPHEADER as usual.
129 NOTE: if you want chunked transfer too, you need to combine these two
130 since you can only set one list of headers with CURLOPT_HTTPHEADER. */
132 /* A less good option would be to enforce HTTP 1.0, but that might also
133 have other implications. */
134 {
135 struct curl_slist *chunk = NULL;
137 chunk = curl_slist_append(chunk, "Expect:");
138 result = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
139 /* use curl_slist_free_all() after the *perform() call to free this
140 list again */
141 }
142#endif
144 /* Perform the request, result gets the return code */
145 result = curl_easy_perform(curl);
146 /* Check for errors */
147 if(result != CURLE_OK)
148 fprintf(stderr, "curl_easy_perform() failed: %s\n",
149 curl_easy_strerror(result));
151 /* always cleanup */
152 curl_easy_cleanup(curl);
153 }
154 curl_global_cleanup();
155 return 0;
156}
Diagnostics4 git calls · 742 ms
CallStatusSizeTime0742 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.3 KiB736 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=736 git.response.bytes=2304 git.response.cache=MISS git.response.duration_ms=736 git.fetch.wants=aaed0aaa063c30dfbe1f3c0990d765bf748c851e 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=2304 git.pkt.payload.max=2283 git.sideband.band1.bytes=2282 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
- a5e1aa02e9812c38
- Request
- eb16e983…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format