| 1 |
.\" ************************************************************************** |
| 2 |
.\" * _ _ ____ _ |
| 3 |
.\" * Project ___| | | | _ \| | |
| 4 |
.\" * / __| | | | |_) | | |
| 5 |
.\" * | (__| |_| | _ <| |___ |
| 6 |
.\" * \___|\___/|_| \_\_____| |
| 7 |
.\" * |
| 8 |
.\" * Copyright (C) 1998 - 2015, Daniel Stenberg, <[email protected]>, et al. |
| 9 |
.\" * |
| 10 |
.\" * This software is licensed as described in the file COPYING, which |
| 11 |
.\" * you should have received as part of this distribution. The terms |
| 12 |
.\" * are also available at https://curl.haxx.se/docs/copyright.html. |
| 13 |
.\" * |
| 14 |
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
| 15 |
.\" * copies of the Software, and permit persons to whom the Software is |
| 16 |
.\" * furnished to do so, under the terms of the COPYING file. |
| 17 |
.\" * |
| 18 |
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 |
.\" * KIND, either express or implied. |
| 20 |
.\" * |
| 21 |
.\" ************************************************************************** |
| 22 |
.\" |
| 23 |
.TH CURLMOPT_PUSHFUNCTION 3 "1 Jun 2015" "libcurl 7.44.0" "curl_multi_setopt options" |
| 24 |
.SH NAME |
| 25 |
CURLMOPT_PUSHFUNCTION \- callback that approves or denies server pushes |
| 26 |
.SH SYNOPSIS |
| 27 |
.nf |
| 28 |
#include <curl/curl.h> |
| 29 |
|
| 30 |
char *curl_pushheader_bynum(struct curl_pushheaders *h, size_t num); |
| 31 |
char *curl_pushheader_byname(struct curl_pushheaders *h, const char *name); |
| 32 |
|
| 33 |
int curl_push_callback(CURL *parent, |
| 34 |
CURL *easy, |
| 35 |
size_t num_headers, |
| 36 |
struct curl_pushheaders *headers, |
| 37 |
void *userp); |
| 38 |
|
| 39 |
CURLMcode curl_multi_setopt(CURLM *handle, CURLMOPT_PUSHFUNCTION, |
| 40 |
curl_push_callback func); |
| 41 |
.fi |
| 42 |
.SH DESCRIPTION |
| 43 |
This callback gets called when a new HTTP/2 stream is being pushed by the |
| 44 |
server (using the PUSH_PROMISE frame). If no push callback is set, all offered |
| 45 |
pushes will be denied automatically. |
| 46 |
.SH CALLBACK DESCRIPTION |
| 47 |
The callback gets its arguments like this: |
| 48 |
|
| 49 |
\fIparent\fP is the handle of the stream on which this push arrives. The new |
| 50 |
handle has been duphandle()d from the parent, meaning that it has gotten all |
| 51 |
its options inherited. It is then up to the application to alter any options |
| 52 |
if desired. |
| 53 |
|
| 54 |
\fIeasy\fP is a newly created handle that represents this upcoming transfer. |
| 55 |
|
| 56 |
\fInum_headers\fP is the number of name+value pairs that was received and can |
| 57 |
be accessed |
| 58 |
|
| 59 |
\fIheaders\fP is a handle used to access push headers using the accessor |
| 60 |
functions described below. This only accesses and provides the PUSH_PROMISE |
| 61 |
headers, the normal response headers will be provided in the header callback |
| 62 |
as usual. |
| 63 |
|
| 64 |
\fIuserp\fP is the pointer set with \fICURLMOPT_PUSHDATA(3)\fP |
| 65 |
|
| 66 |
If the callback returns CURL_PUSH_OK, the 'easy' handle will be added to the |
| 67 |
multi handle, the callback must not do that by itself. |
| 68 |
|
| 69 |
The callback can access PUSH_PROMISE headers with two accessor |
| 70 |
functions. These functions can only be used from within this callback and they |
| 71 |
can only access the PUSH_PROMISE headers. The normal response headers will be |
| 72 |
passed to the header callback for pushed streams just as for normal streams. |
| 73 |
.IP curl_pushheader_bynum |
| 74 |
Returns the header at index 'num' (or NULL). The returned pointer points to a |
| 75 |
"name:value" string that will be freed when this callback returns. |
| 76 |
.IP curl_pushheader_byname |
| 77 |
Returns the value for the given header name (or NULL). This is a shortcut so |
| 78 |
that the application doesn't have to loop through all headers to find the one |
| 79 |
it is interested in. The data pointed will be freed when this callback |
| 80 |
returns. If more than one header field use the same name, this returns only |
| 81 |
the first one. |
| 82 |
.SH CALLBACK RETURN VALUE |
| 83 |
.IP "CURL_PUSH_OK (0)" |
| 84 |
The application has accepted the stream and it can now start receiving data, |
| 85 |
the ownership of the CURL handle has been taken over by the application. |
| 86 |
.IP "CURL_PUSH_DENY (1)" |
| 87 |
The callback denies the stream and no data for this will reach the |
| 88 |
application, the easy handle will be destroyed by libcurl. |
| 89 |
.IP * |
| 90 |
All other return codes are reserved for future use. |
| 91 |
.SH DEFAULT |
| 92 |
NULL, no callback |
| 93 |
.SH PROTOCOLS |
| 94 |
HTTP(S) (HTTP/2 only) |
| 95 |
.SH EXAMPLE |
| 96 |
.nf |
| 97 |
/* only allow pushes for file names starting with "push-" */ |
| 98 |
int push_callback(CURL *parent, |
| 99 |
CURL *easy, |
| 100 |
size_t num_headers, |
| 101 |
struct curl_pushheaders *headers, |
| 102 |
void *userp) |
| 103 |
{ |
| 104 |
char *headp; |
| 105 |
int *transfers = (int *)userp; |
| 106 |
FILE *out; |
| 107 |
headp = curl_pushheader_byname(headers, ":path"); |
| 108 |
if(headp && !strncmp(headp, "/push-", 6)) { |
| 109 |
fprintf(stderr, "The PATH is %s\\n", headp); |
| 110 |
|
| 111 |
/* save the push here */ |
| 112 |
out = fopen("pushed-stream", "wb"); |
| 113 |
|
| 114 |
/* write to this file */ |
| 115 |
curl_easy_setopt(easy, CURLOPT_WRITEDATA, out); |
| 116 |
|
| 117 |
(*transfers)++; /* one more */ |
| 118 |
|
| 119 |
return CURL_PUSH_OK; |
| 120 |
} |
| 121 |
return CURL_PUSH_DENY; |
| 122 |
} |
| 123 |
|
| 124 |
curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback); |
| 125 |
curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter); |
| 126 |
.fi |
| 127 |
.SH AVAILABILITY |
| 128 |
Added in 7.44.0 |
| 129 |
.SH RETURN VALUE |
| 130 |
Returns CURLM_OK if the option is supported, and CURLM_UNKNOWN_OPTION if not. |
| 131 |
.SH "SEE ALSO" |
| 132 |
.BR CURLMOPT_PUSHDATA "(3), " CURLMOPT_PIPELINING "(3), " CURLOPT_PIPEWAIT "(3), " |
| 133 |
.BR RFC 7540 |