Artifactspublic-v0

curl

master
ply4 git calls26 ms289 KiB3 cachedprotocol v2
159 lines4.8 KiBRaw
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 * Performs an FTP upload and renames the file after a successful transfer.
26 * </DESC>
27 */
28#ifdef _MSC_VER
29#ifndef _CRT_SECURE_NO_WARNINGS
30#define _CRT_SECURE_NO_WARNINGS /* for fopen(), strerror() */
31#endif
32#endif
34#include <stdio.h>
35#include <string.h>
36#include <errno.h>
37#include <fcntl.h>
38#include <sys/stat.h>
39#include <sys/types.h>
41#include <curl/curl.h>
43#ifdef _WIN32
44#include <io.h>
45#undef stat
46#define stat _stati64
47#undef fstat
48#define fstat _fstati64
49#define fileno _fileno
50#else
51#include <unistd.h>
52#endif
54#define LOCAL_FILE "/tmp/uploadthis.txt"
55#define UPLOAD_FILE_AS "while-uploading.txt"
56#define REMOTE_URL "ftp://example.com/" UPLOAD_FILE_AS
57#define RENAME_FILE_TO "renamed-and-fine.txt"
59/* NOTE: if you want this example to work on Windows with libcurl as a DLL,
60 you MUST also provide a read callback with CURLOPT_READFUNCTION. Failing to
61 do so might give you a crash since a DLL may not use the variable's memory
62 when passed in to it from an app like this. */
63static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *stream)
65 unsigned long nread;
66 /* in real-world cases, this would probably get this data differently
67 as this fread() stuff is exactly what the library already would do
68 by default internally */
69 size_t retcode = fread(ptr, size, nmemb, stream);
71 if(retcode > 0) {
72 nread = (unsigned long)retcode;
73 fprintf(stderr, "*** We read %lu bytes from file\n", nread);
74 }
76 return retcode;
79int main(void)
81 CURL *curl;
82 CURLcode result;
83 FILE *hd_src;
84 struct stat file_info;
85 curl_off_t fsize;
87 struct curl_slist *headerlist = NULL;
88 static const char buf_1[] = "RNFR " UPLOAD_FILE_AS;
89 static const char buf_2[] = "RNTO " RENAME_FILE_TO;
91 /* get a FILE * of the file */
92 hd_src = fopen(LOCAL_FILE, "rb");
93 if(!hd_src) {
94 printf("Could not open '%s': %s\n", LOCAL_FILE, strerror(errno));
95 return 2;
96 }
98 /* to get the file size */
99 if(fstat(fileno(hd_src), &file_info)) {
100 fclose(hd_src);
101 return 1; /* cannot continue */
102 }
103 fsize = file_info.st_size;
105 printf("Local file size: %" CURL_FORMAT_CURL_OFF_T " bytes.\n", fsize);
107 /* In Windows, this inits the Winsock stuff */
108 result = curl_global_init(CURL_GLOBAL_ALL);
109 if(result != CURLE_OK) {
110 fclose(hd_src);
111 return (int)result;
112 }
114 /* get a curl handle */
115 curl = curl_easy_init();
116 if(curl) {
117 /* build a list of commands to pass to libcurl */
118 headerlist = curl_slist_append(headerlist, buf_1);
119 headerlist = curl_slist_append(headerlist, buf_2);
121 /* we want to use our own read function */
122 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
124 /* enable uploading */
125 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
127 /* specify target */
128 curl_easy_setopt(curl, CURLOPT_URL, REMOTE_URL);
130 /* pass in that last of FTP commands to run after the transfer */
131 curl_easy_setopt(curl, CURLOPT_POSTQUOTE, headerlist);
133 /* now specify which file to upload */
134 curl_easy_setopt(curl, CURLOPT_READDATA, hd_src);
136 /* Set the size of the file to upload (optional). If you give a *_LARGE
137 option you MUST make sure that the type of the passed-in argument is a
138 curl_off_t. If you use CURLOPT_INFILESIZE (without _LARGE) you must
139 make sure that to pass in a type 'long' argument. */
140 curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, fsize);
142 /* Now run off and do what you have been told! */
143 result = curl_easy_perform(curl);
144 /* Check for errors */
145 if(result != CURLE_OK)
146 fprintf(stderr, "curl_easy_perform() failed: %s\n",
147 curl_easy_strerror(result));
149 /* clean up the FTP commands list */
150 curl_slist_free_all(headerlist);
152 /* always cleanup */
153 curl_easy_cleanup(curl);
154 }
155 fclose(hd_src); /* close the local file */
157 curl_global_cleanup();
158 return (int)result;
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 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=86
Open pack map
fetch2002.1 KiB · hit20 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=20
git.response.bytes=2200
git.response.cache=HIT
git.response.duration_ms=20
git.fetch.wants=07546f313e901760480b2fb1333a1a0b01239c09
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=2200
git.pkt.payload.max=2179
git.sideband.band1.bytes=2178
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
a5e29ef3ec981293
Request
c4f18bfd…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format