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