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