Artifactspublic-v0

curl

master
ply4 git calls185 ms289 KiB2 cachedprotocol v2
222 lines5.1 KiBRaw

NAME

CURLOPT_DEBUGFUNCTION - debug callback

SYNOPSIS

c
#include <curl/curl.h>

typedef enum {
  CURLINFO_TEXT = 0,
  CURLINFO_HEADER_IN,    /* 1 */
  CURLINFO_HEADER_OUT,   /* 2 */
  CURLINFO_DATA_IN,      /* 3 */
  CURLINFO_DATA_OUT,     /* 4 */
  CURLINFO_SSL_DATA_IN,  /* 5 */
  CURLINFO_SSL_DATA_OUT, /* 6 */
  CURLINFO_END
} curl_infotype;

int debug_callback(CURL *handle,
                   curl_infotype type,
                   char *data,
                   size_t size,
                   void *clientp);

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
                          debug_callback);

DESCRIPTION

Pass a pointer to your callback function, which should match the prototype shown above.

CURLOPT_DEBUGFUNCTION(3) replaces the standard debug function used when CURLOPT_VERBOSE(3) is in effect. This callback receives debug information, as specified in the type argument. This function must return 0. The data pointed to by the char * passed to this function is not null-terminated, but is exactly of the size as told by the size argument.

WARNING: this callback may receive sensitive contents from headers and data, including information sent as CURLINFO_TEXT.

The clientp argument is the pointer set with CURLOPT_DEBUGDATA(3).

Available curl_infotype values:

CURLINFO_TEXT

The data is informational text.

CURLINFO_HEADER_IN

The data is header (or header-like) data received from the peer.

CURLINFO_HEADER_OUT

The data is header (or header-like) data sent to the peer.

CURLINFO_DATA_IN

The data is the unprocessed protocol data received from the peer. Even if the data is encoded or compressed, it is not provided decoded nor decompressed to this callback. If you need the data in decoded and decompressed form, use CURLOPT_WRITEFUNCTION(3).

CURLINFO_DATA_OUT

The data is protocol data sent to the peer.

CURLINFO_SSL_DATA_OUT

The data is SSL/TLS (binary) data sent to the peer.

CURLINFO_SSL_DATA_IN

The data is SSL/TLS (binary) data received from the peer.

WARNING: This callback may be called with the curl handle set to an internal handle. (Added in 8.4.0)

If you need to distinguish your curl handle from internal handles then set CURLOPT_PRIVATE(3) on your handle.

DEFAULT

NULL

%PROTOCOLS%

EXAMPLE

c
static void dump(const char *text,
                 FILE *stream, unsigned char *ptr, size_t size)
{
  size_t i;
  size_t c;
  unsigned int width = 0x10;

  fprintf(stream, "%s, %lu bytes (0x%lx)\n",
          text, (unsigned long)size, (unsigned long)size);

  for(i = 0; i < size; i += width) {
    fprintf(stream, "%4.4lx: ", (unsigned long)i);

    /* show hex to the left */
    for(c = 0; c < width; c++) {
      if(i + c < size)
        fprintf(stream, "%02x ", ptr[i + c]);
      else
        fputs("   ", stream);
    }

    /* show data on the right */
    for(c = 0; (c < width) && (i + c < size); c++) {
      char x = (ptr[i + c] >= 0x20 && ptr[i + c] < 0x80)
               ? (char)ptr[i + c] : '.';
      fputc(x, stream);
    }

    fputc('\n', stream); /* newline */
  }
}

static int my_trace(CURL *handle, curl_infotype type,
                    char *data, size_t size,
                    void *clientp)
{
  const char *text;
  (void)handle;
  (void)clientp;

  switch(type) {
  case CURLINFO_TEXT:
    fputs("== Info: ", stderr);
    fwrite(data, size, 1, stderr);
    return 0;
  default: /* in case a new one is introduced to shock us */
    return 0;

  case CURLINFO_HEADER_OUT:
    text = "=> Send header";
    break;
  case CURLINFO_DATA_OUT:
    text = "=> Send data";
    break;
  case CURLINFO_SSL_DATA_OUT:
    text = "=> Send SSL data";
    break;
  case CURLINFO_HEADER_IN:
    text = "<= Recv header";
    break;
  case CURLINFO_DATA_IN:
    text = "<= Recv data";
    break;
  case CURLINFO_SSL_DATA_IN:
    text = "<= Recv SSL data";
    break;
  }

  dump(text, stderr, (unsigned char *)data, size);
  return 0;
}

int main(void)
{
  CURL *curl;
  CURLcode result;

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);

    /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

    /* example.com is redirected, so we tell libcurl to follow redirection */
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
    result = curl_easy_perform(curl);
    /* Check for errors */
    if(result != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(result));

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

%AVAILABILITY%

RETURN VALUE

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK, non-zero means an error occurred, see libcurl-errors(3).

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_DEBUGFUNCTION
5Section: 3
6Source: libcurl
7See-also:
8 - CURLINFO_CONN_ID (3)
9 - CURLINFO_XFER_ID (3)
10 - CURLOPT_DEBUGDATA (3)
11 - CURLOPT_VERBOSE (3)
12 - curl_global_trace (3)
13Protocol:
14 - All
15Added-in: 7.9.6
16---
18# NAME
20CURLOPT_DEBUGFUNCTION - debug callback
22# SYNOPSIS
24~~~c
25#include <curl/curl.h>
27typedef enum {
28 CURLINFO_TEXT = 0,
29 CURLINFO_HEADER_IN, /* 1 */
30 CURLINFO_HEADER_OUT, /* 2 */
31 CURLINFO_DATA_IN, /* 3 */
32 CURLINFO_DATA_OUT, /* 4 */
33 CURLINFO_SSL_DATA_IN, /* 5 */
34 CURLINFO_SSL_DATA_OUT, /* 6 */
35 CURLINFO_END
36} curl_infotype;
38int debug_callback(CURL *handle,
39 curl_infotype type,
40 char *data,
41 size_t size,
42 void *clientp);
44CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
45 debug_callback);
46~~~
48# DESCRIPTION
50Pass a pointer to your callback function, which should match the prototype
51shown above.
53CURLOPT_DEBUGFUNCTION(3) replaces the standard debug function used when
54CURLOPT_VERBOSE(3) is in effect. This callback receives debug information, as
55specified in the *type* argument. This function must return 0. The *data*
56pointed to by the char * passed to this function is not null-terminated, but
57is exactly of the *size* as told by the *size* argument.
59**WARNING:** this callback may receive sensitive contents from headers and
60data, including information sent as **CURLINFO_TEXT**.
62The *clientp* argument is the pointer set with CURLOPT_DEBUGDATA(3).
64Available **curl_infotype** values:
66## CURLINFO_TEXT
68The data is informational text.
70## CURLINFO_HEADER_IN
72The data is header (or header-like) data received from the peer.
74## CURLINFO_HEADER_OUT
76The data is header (or header-like) data sent to the peer.
78## CURLINFO_DATA_IN
80The data is the unprocessed protocol data received from the peer. Even if the
81data is encoded or compressed, it is not provided decoded nor decompressed
82to this callback. If you need the data in decoded and decompressed form, use
83CURLOPT_WRITEFUNCTION(3).
85## CURLINFO_DATA_OUT
87The data is protocol data sent to the peer.
89## CURLINFO_SSL_DATA_OUT
91The data is SSL/TLS (binary) data sent to the peer.
93## CURLINFO_SSL_DATA_IN
95The data is SSL/TLS (binary) data received from the peer.
97##
99**WARNING:** This callback may be called with the curl *handle* set to an
100internal handle. (Added in 8.4.0)
102If you need to distinguish your curl *handle* from internal handles then set
103CURLOPT_PRIVATE(3) on your handle.
105# DEFAULT
107NULL
109# %PROTOCOLS%
111# EXAMPLE
113~~~c
114static void dump(const char *text,
115 FILE *stream, unsigned char *ptr, size_t size)
117 size_t i;
118 size_t c;
119 unsigned int width = 0x10;
121 fprintf(stream, "%s, %lu bytes (0x%lx)\n",
122 text, (unsigned long)size, (unsigned long)size);
124 for(i = 0; i < size; i += width) {
125 fprintf(stream, "%4.4lx: ", (unsigned long)i);
127 /* show hex to the left */
128 for(c = 0; c < width; c++) {
129 if(i + c < size)
130 fprintf(stream, "%02x ", ptr[i + c]);
131 else
132 fputs(" ", stream);
133 }
135 /* show data on the right */
136 for(c = 0; (c < width) && (i + c < size); c++) {
137 char x = (ptr[i + c] >= 0x20 && ptr[i + c] < 0x80)
138 ? (char)ptr[i + c] : '.';
139 fputc(x, stream);
140 }
142 fputc('\n', stream); /* newline */
143 }
146static int my_trace(CURL *handle, curl_infotype type,
147 char *data, size_t size,
148 void *clientp)
150 const char *text;
151 (void)handle;
152 (void)clientp;
154 switch(type) {
155 case CURLINFO_TEXT:
156 fputs("== Info: ", stderr);
157 fwrite(data, size, 1, stderr);
158 return 0;
159 default: /* in case a new one is introduced to shock us */
160 return 0;
162 case CURLINFO_HEADER_OUT:
163 text = "=> Send header";
164 break;
165 case CURLINFO_DATA_OUT:
166 text = "=> Send data";
167 break;
168 case CURLINFO_SSL_DATA_OUT:
169 text = "=> Send SSL data";
170 break;
171 case CURLINFO_HEADER_IN:
172 text = "<= Recv header";
173 break;
174 case CURLINFO_DATA_IN:
175 text = "<= Recv data";
176 break;
177 case CURLINFO_SSL_DATA_IN:
178 text = "<= Recv SSL data";
179 break;
180 }
182 dump(text, stderr, (unsigned char *)data, size);
183 return 0;
186int main(void)
188 CURL *curl;
189 CURLcode result;
191 curl = curl_easy_init();
192 if(curl) {
193 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
195 /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
196 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
198 /* example.com is redirected, so we tell libcurl to follow redirection */
199 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
201 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
202 result = curl_easy_perform(curl);
203 /* Check for errors */
204 if(result != CURLE_OK)
205 fprintf(stderr, "curl_easy_perform() failed: %s\n",
206 curl_easy_strerror(result));
208 /* always cleanup */
209 curl_easy_cleanup(curl);
210 }
211 return 0;
213~~~
215# %AVAILABILITY%
217# RETURN VALUE
219curl_easy_setopt(3) returns a CURLcode indicating success or error.
221CURLE_OK (0) means everything was OK, non-zero means an error occurred, see
222libcurl-errors(3).
Diagnostics4 git calls · 185 ms
CallStatusSizeTime0185 ms
discover200152 B3 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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=180
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=2
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 KiB180 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2164
git.response.cache=MISS
git.response.duration_ms=180
git.fetch.wants=e66a470f6ada88ec4a7307b5c5822ed9587db63f
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=2164
git.pkt.payload.max=2143
git.sideband.band1.bytes=2142
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
a5e320d18ffa9de8
Request
38712a8a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format