curl_pushheader_byname.md (1994B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: curl_pushheader_byname 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLMOPT_PUSHFUNCTION (3) 9 - curl_pushheader_bynum (3) 10 Protocol: 11 - HTTP 12 Added-in: 7.44.0 13 --- 14 15 # NAME 16 17 curl_pushheader_byname - get a push header by name 18 19 # SYNOPSIS 20 21 ~~~c 22 #include <curl/curl.h> 23 24 char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name); 25 ~~~ 26 27 # DESCRIPTION 28 29 This is a function that is only functional within a 30 CURLMOPT_PUSHFUNCTION(3) callback. It makes no sense to try to use it 31 elsewhere and it has no function then. 32 33 It returns the value for the given header field name (or NULL) for the 34 incoming server push request. This is a shortcut so that the application does 35 not have to loop through all headers to find the one it is interested in. The 36 data this function points to is freed when this callback returns. If more than 37 one 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 46 static 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 72 int 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 85 Returns a pointer to the header field content or NULL.