cURL / Mailing Lists / curl-library / Single Mail

curl-library

HTTP/2 server push, take #2

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 29 May 2015 13:25:31 +0200 (CEST)

Hi again!

Here follows suggestion version 2. The changes:

  - no stream id shown
  - provide parent stream handle too for callback
  - pass in handle to access all and any header with
    acessor functions
  - inherit options from parent by default to new handle

HTTP/2 server push
==================

- CURLMOPT_PUSHFUNCTION [callback]
   CURLMOPT_PUSHDATA [callback pointer]

These are two new options for curl_multi_setopt()

Without the CURLMOPT_PUSHFUNCTION set, pushed streams will be refused.

   int curl_push_func(CURL *parent,
                      CURL *easy,
                      int num_headers,
                      struct curl_pushheaders *headers,
                      void *userp);

This callback gets called when a new stream is being pushed by the server.

  'easy' is a newly created handle that represents this new transfer.

  'parent' is the handle of the stream on which this push arrives. The new
handle has been duphandle()d from the parent, meaning that it has gotten all
its options inherited. It is then up to the application to alter any options
if desired.

  'num_headers' is the number of name+value pairs that was received and can be
accessed

  'headers' is a handle used to access push headers using the accessor
functions described below

  'userp' is the pointer set with CURLMOPT_PUSHDATA

If the callback returns CURL_PUSH_OK, the 'easy' handle will be added to the
multi handle, the callback must not do that by itself.

Header Accessors
================

Accessor functions to read headers from within the push callback (and *only*
within the callback):

   struct curl_headerpair *curl_pushheader_bynum(push_headers, int num);

Returns the header pair at index 'num' (or NULL). The returned pointer points
to a struct that will be freed when this callback returns. A header pair is
both name and value. Using this function, the application code can iterate
over all headers received in the PUSH_PROMISE.

   struct curl_headerpair *curl_pushheader_byname(push_headers, char *name);

Returns the header pair for the given header name (or NULL). This is a
shortcut so that the application doesn't have to loop through all headers to
find the one it is interested in.

struct curl_headerpair {
    unsigned char *name; /* zero terminated name */
    size_t namelen; /* length of 'name' */
    unsigned char *value; /* zero terminated name */
    size_t valuelen; /* length of 'value' */
};

Callback return codes
=====================

CURL_PUSH_OK - we have accepted the stream and it can now start receiving
                  data, the ownership of the CURL handle has been taken over by
                  the application.

CURL_PUSH_DENY - the callback denies the stream and no data for this will
                  reach the application, the easy handle will be destroyed by
                  libcurl

  * - all other return codes are reserved for future use

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2015-05-29