• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: curl_pushheader_byname
5Section: 3
6Source: libcurl
7See-also:
8  - CURLMOPT_PUSHFUNCTION (3)
9  - curl_pushheader_bynum (3)
10---
11
12# NAME
13
14curl_pushheader_byname - get a push header by name
15
16# SYNOPSIS
17
18~~~c
19#include <curl/curl.h>
20
21char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name);
22~~~
23
24# DESCRIPTION
25
26This is a function that is only functional within a
27CURLMOPT_PUSHFUNCTION(3) callback. It makes no sense to try to use it
28elsewhere and it has no function then.
29
30It returns the value for the given header field name (or NULL) for the
31incoming server push request. This is a shortcut so that the application does
32not have to loop through all headers to find the one it is interested in. The
33data this function points to is freed when this callback returns. If more than
34one header field use the same name, this returns only the first one.
35
36# EXAMPLE
37
38~~~c
39#include <string.h> /* for strncmp */
40
41static int push_cb(CURL *parent,
42                   CURL *easy,
43                   size_t num_headers,
44                   struct curl_pushheaders *headers,
45                   void *clientp)
46{
47  char *headp;
48  int *transfers = (int *)clientp;
49  FILE *out;
50  headp = curl_pushheader_byname(headers, ":path");
51  if(headp && !strncmp(headp, "/push-", 6)) {
52    fprintf(stderr, "The PATH is %s\n", headp);
53
54    /* save the push here */
55    out = fopen("pushed-stream", "wb");
56
57    /* write to this file */
58    curl_easy_setopt(easy, CURLOPT_WRITEDATA, out);
59
60    (*transfers)++; /* one more */
61
62    return CURL_PUSH_OK;
63  }
64  return CURL_PUSH_DENY;
65}
66
67int main(void)
68{
69  int counter;
70  CURLM *multi = curl_multi_init();
71  curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_cb);
72  curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter);
73}
74~~~
75
76# AVAILABILITY
77
78Added in 7.44.0
79
80# RETURN VALUE
81
82Returns a pointer to the header field content or NULL.
83