From c712aa0ebef564b2164e204fbbc744e08a072276 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 2 Jun 2015 11:58:39 +0200 Subject: [PATCH] CURLMOPT_PUSHFUNCTION.3: added example --- docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 | 33 ++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 b/docs/libcurl/opts/CURLMOPT_PUSHFUNCTION.3 index 3d87e2344aff87..24ebfb0e7c7a83 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