2 nghttp2_select_next_protocol
3 ============================
8 *#include <nghttp2/nghttp2.h>*
10 .. function:: int nghttp2_select_next_protocol(unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen)
13 A helper function for dealing with NPN in client side or ALPN in
14 server side. The *in* contains peer's protocol list in preferable
15 order. The format of *in* is length-prefixed and not
16 null-terminated. For example, ``h2`` and
17 ``http/1.1`` stored in *in* like this::
22 in[4..11] = "http/1.1"
25 The selection algorithm is as follows:
27 1. If peer's list contains HTTP/2 protocol the library supports,
28 it is selected and returns 1. The following step is not taken.
30 2. If peer's list contains ``http/1.1``, this function selects
31 ``http/1.1`` and returns 0. The following step is not taken.
33 3. This function selects nothing and returns -1 (So called
34 non-overlap case). In this case, *out* and *outlen* are left
37 Selecting ``h2`` means that ``h2`` is written into *\*out* and its
38 length (which is 2) is assigned to *\*outlen*.
40 For ALPN, refer to https://tools.ietf.org/html/rfc7301
42 See http://technotes.googlecode.com/git/nextprotoneg.html for more
45 For NPN, to use this method you should do something like::
47 static int select_next_proto_cb(SSL* ssl,
49 unsigned char *outlen,
50 const unsigned char *in,
55 rv = nghttp2_select_next_protocol(out, outlen, in, inlen);
57 return SSL_TLSEXT_ERR_NOACK;
60 ((MyType*)arg)->http2_selected = 1;
62 return SSL_TLSEXT_ERR_OK;
65 SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);