diff options
author | Daniel Stenberg <daniel@haxx.se> | 2015-06-02 11:58:39 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2015-06-24 23:44:42 +0200 |
commit | c712aa0ebef564b2164e204fbbc744e08a072276 (patch) | |
tree | 12ef4f803bd571da18d97e2f71f5d0ce230b46f8 /docs/libcurl/opts | |
parent | a384f28ca61e5631f81b209a2994eb13b9ac12df (diff) |
CURLMOPT_PUSHFUNCTION.3: added example
Diffstat (limited to 'docs/libcurl/opts')
-rw-r--r-- | docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 b/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 index 3d87e2344..24ebfb0e7 100644 --- a/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 +++ b/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 @@ -92,7 +92,38 @@ NULL, no callback .SH PROTOCOLS HTTP(S) (HTTP/2 only) .SH EXAMPLE -TODO +.nf +/* only allow pushes for file names starting with "push-" */ +int push_callback(CURL *parent, + CURL *easy, + size_t num_headers, + struct curl_pushheaders *headers, + void *userp) +{ + char *headp; + int *transfers = (int *)userp; + char filename[128]; + FILE *out; + headp = curl_pushheader_byname(headers, ":path"); + if(headp && !strncmp(headp, "/push-", 6)) { + fprintf(stderr, "The PATH is %s\n", headp); + + /* save the push here */ + out = fopen("pushed-stream", "wb"); + + /* write to this file */ + curl_easy_setopt(easy, CURLOPT_WRITEDATA, out); + + (*transfers)++; /* one more */ + + return CURL_PUSH_OK; + } + return CURL_PUSH_DENY; +} + +curl_multi_setopt(multi, CURLMOPT_PUSHFUNCTION, push_callback); +curl_multi_setopt(multi, CURLMOPT_PUSHDATA, &counter); +.fi .SH AVAILABILITY Added in 7.44.0 .SH RETURN VALUE |