Artifactspublic-v0

curl

master
ply4 git calls37 ms288 KiB3 cachedprotocol v2
109 lines3.5 KiBRaw

NAME

curl_easy_nextheader - get the next HTTP header

SYNOPSIS

c
#include <curl/curl.h>

struct curl_header *curl_easy_nextheader(CURL *easy,
                                         unsigned int origin,
                                         int request,
                                         struct curl_header *prev);

DESCRIPTION

This function lets an application iterate over all previously received HTTP headers.

The origin argument is for specifying which headers to receive, as a single HTTP transfer might provide headers from several different places and they may then have different importance to the user and headers using the same name might be used. The origin is a bitmask for what header sources you want. See the curl_easy_header(3) man page for the origin descriptions.

The request argument tells libcurl from which request you want headers from. A single transfer might consist of a series of HTTP requests and this argument lets you specify which particular individual request you want the headers from. 0 being the first request and then the number increases for further redirects or when multi-state authentication is used. Passing in -1 is a shortcut to "the last" request in the series, independently of the actual amount of requests used.

It is suggested that you pass in the same origin and request when iterating over a range of headers as changing the value mid-loop might give you unexpected results.

If prev is NULL, this function returns a pointer to the first header stored within the given scope (origin + request).

If prev is a pointer to a previously returned header struct, curl_easy_nextheader(3) returns a pointer the next header stored within the given scope. This way, an application can iterate over all available headers.

The memory for the struct this points to, is owned and managed by libcurl and is associated with the easy handle. Applications must copy the data if they want it to survive subsequent API calls or the life-time of the easy handle.

The prev pointer is only valid until another transfer is done using the easy handle. Once a new transfer has started, a new prev must be retrieved by calling curl_easy_nextheader(3) again with NULL as the fourth argument.

%PROTOCOLS%

EXAMPLE

c
int main(void)
{
  struct curl_header *prev = NULL;
  struct curl_header *h;

  CURL *curl = curl_easy_init();
  if(curl) {
    unsigned int origin;

    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    curl_easy_perform(curl);

    /* extract the normal headers from the first request */
    while((h = curl_easy_nextheader(curl, CURLH_HEADER, 0, prev))) {
      printf("%s: %s\n", h->name, h->value);
      prev = h;
    }

    /* extract the normal headers + 1xx + trailers from the last request */
    origin = CURLH_HEADER | CURLH_1XX | CURLH_TRAILER;
    while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
      printf("%s: %s\n", h->name, h->value);
      prev = h;
    }
  }
}

%AVAILABILITY%

RETURN VALUE

This function returns the next header, or NULL when there are no more (matching) headers or an error occurred.

If this function returns NULL when prev was set to NULL, then there are no headers available within the scope to return.

1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_easy_nextheader
5Section: 3
6Source: libcurl
7See-also:
8 - curl_easy_header (3)
9 - curl_easy_perform (3)
10Protocol:
11 - HTTP
12Added-in: 7.83.0
13---
15# NAME
17curl_easy_nextheader - get the next HTTP header
19# SYNOPSIS
21~~~c
22#include <curl/curl.h>
24struct curl_header *curl_easy_nextheader(CURL *easy,
25 unsigned int origin,
26 int request,
27 struct curl_header *prev);
28~~~
30# DESCRIPTION
32This function lets an application iterate over all previously received HTTP
33headers.
35The *origin* argument is for specifying which headers to receive, as a single
36HTTP transfer might provide headers from several different places and they may
37then have different importance to the user and headers using the same name
38might be used. The *origin* is a bitmask for what header sources you want. See
39the curl_easy_header(3) man page for the origin descriptions.
41The *request* argument tells libcurl from which request you want headers
42from. A single transfer might consist of a series of HTTP requests and this
43argument lets you specify which particular individual request you want the
44headers from. 0 being the first request and then the number increases for
45further redirects or when multi-state authentication is used. Passing in -1 is
46a shortcut to "the last" request in the series, independently of the actual
47amount of requests used.
49It is suggested that you pass in the same **origin** and **request** when
50iterating over a range of headers as changing the value mid-loop might give
51you unexpected results.
53If *prev* is NULL, this function returns a pointer to the first header stored
54within the given scope (origin + request).
56If *prev* is a pointer to a previously returned header struct,
57curl_easy_nextheader(3) returns a pointer the next header stored within the
58given scope. This way, an application can iterate over all available headers.
60The memory for the struct this points to, is owned and managed by libcurl and
61is associated with the easy handle. Applications must copy the data if they
62want it to survive subsequent API calls or the life-time of the easy handle.
64The *prev* pointer is only valid until another transfer is done using the
65*easy* handle. Once a new transfer has started, a new *prev* must be retrieved
66by calling curl_easy_nextheader(3) again with NULL as the fourth argument.
68# %PROTOCOLS%
70# EXAMPLE
72~~~c
73int main(void)
75 struct curl_header *prev = NULL;
76 struct curl_header *h;
78 CURL *curl = curl_easy_init();
79 if(curl) {
80 unsigned int origin;
82 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
83 curl_easy_perform(curl);
85 /* extract the normal headers from the first request */
86 while((h = curl_easy_nextheader(curl, CURLH_HEADER, 0, prev))) {
87 printf("%s: %s\n", h->name, h->value);
88 prev = h;
89 }
91 /* extract the normal headers + 1xx + trailers from the last request */
92 origin = CURLH_HEADER | CURLH_1XX | CURLH_TRAILER;
93 while((h = curl_easy_nextheader(curl, origin, -1, prev))) {
94 printf("%s: %s\n", h->name, h->value);
95 prev = h;
96 }
97 }
99~~~
101# %AVAILABILITY%
103# RETURN VALUE
105This function returns the next header, or NULL when there are no more
106(matching) headers or an error occurred.
108If this function returns NULL when *prev* was set to NULL, then there are no
109headers available within the scope to return.
Diagnostics4 git calls · 37 ms
CallStatusSizeTime037 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 · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=33
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
fetch2001.6 KiB · hit33 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1624
git.response.cache=HIT
git.response.duration_ms=33
git.fetch.wants=1a07f1fe31d841c28595729971f79c38d900f2b6
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=1624
git.pkt.payload.max=1603
git.sideband.band1.bytes=1602
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
a5e32290894c5aae
Request
ba850443…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format