Imported Upstream version 7.44.0
[platform/upstream/curl.git] / docs / HTTP2.md
1 HTTP/2 with curl
2 ================
3
4 [HTTP/2 Spec](https://www.rfc-editor.org/rfc/rfc7540.txt)
5 [http2 explained](http://daniel.haxx.se/http2/)
6
7 Build prerequisites
8 -------------------
9   - nghttp2
10   - OpenSSL, NSS, GnutTLS or PolarSSL with a new enough version
11
12 [nghttp2](https://nghttp2.org/)
13 -------------------------------
14
15 libcurl uses this 3rd party library for the low level protocol handling
16 parts. The reason for this is that HTTP/2 is much more complex at that layer
17 than HTTP/1.1 (which we implement on our own) and that nghttp2 is an already
18 existing and well functional library.
19
20 We require at least version 1.0.0.
21
22 Over an http:// URL
23 -------------------
24
25 If `CURLOPT_HTTP_VERSION` is set to `CURL_HTTP_VERSION_2_0`, libcurl will
26 include an upgrade header in the initial request to the host to allow
27 upgrading to HTTP/2.
28
29 Possibly we can later introduce an option that will cause libcurl to fail if
30 not possible to upgrade. Possibly we introduce an option that makes libcurl
31 use HTTP/2 at once over http://
32
33 Over an https:// URL
34 --------------------
35
36 If `CURLOPT_HTTP_VERSION` is set to `CURL_HTTP_VERSION_2_0`, libcurl will use
37 ALPN (or NPN) to negotiate which protocol to continue with. Possibly introduce
38 an option that will cause libcurl to fail if not possible to use HTTP/2.
39 Consider options to explicitly disable ALPN and/or NPN.
40
41 ALPN is the TLS extension that HTTP/2 is expected to use. The NPN extension is
42 for a similar purpose, was made prior to ALPN and is used for SPDY so early
43 HTTP/2 servers are implemented using NPN before ALPN support is widespread.
44
45 SSL libs
46 --------
47
48 The challenge is the ALPN and NPN support and all our different SSL
49 backends. You may need a fairly updated SSL library version for it to
50 provide the necessary TLS features. Right now we support:
51
52   - OpenSSL:  ALPN and NPN
53   - NSS:      ALPN and NPN
54   - GnuTLS:   ALPN
55   - PolarSSL: ALPN
56
57 Multiplexing
58 ------------
59
60 Starting in 7.43.0, libcurl fully supports HTTP/2 multiplexing, which is the
61 term for doing multiple independent transfers over the same physical TCP
62 connection.
63
64 To take advantage of multiplexing, you need to use the multi interface and set
65 `CURLMOPT_PIPELINING` to `CURLPIPE_MULTIPLEX`. With that bit set, libcurl will
66 attempt to re-use existing HTTP/2 connections and just add a new stream over
67 that when doing subsequent parallel requests.
68
69 While libcurl sets up a connection to a HTTP server there is a period during
70 which it doesn't know if it can pipeline or do multiplexing and if you add new
71 transfers in that period, libcurl will default to start new connections for
72 those transfers. With the new option `CURLOPT_PIPEWAIT` (added in 7.43.0), you
73 can ask that a transfer should rather wait and see in case there's a
74 connection for the same host in progress that might end up being possible to
75 multiplex on. It favours keeping the number of connections low to the cost of
76 slightly longer time to first byte transferred.
77
78 Applications
79 ------------
80
81 We hide HTTP/2's binary nature and convert received HTTP/2 traffic to headers
82 in HTTP 1.1 style. This allows applications to work unmodified.
83
84 curl tool
85 ---------
86
87 curl offers the `--http2` command line option to enable use of HTTP/2
88
89 HTTP Alternative Services
90 -------------------------
91
92 Alt-Svc is a suggested extension with a corresponding frame (ALTSVC) in HTTP/2
93 that tells the client about an alternative "route" to the same content for the
94 same origin server that you get the response from. A browser or long-living
95 client can use that hint to create a new connection asynchronously.  For
96 libcurl, we may introduce a way to bring such clues to the applicaton and/or
97 let a subsequent request use the alternate route
98 automatically. [Spec](https://tools.ietf.org/html/draft-ietf-httpbis-alt-svc-05)
99
100 TODO
101 ----
102
103   - Provide API to set priorities / dependencies of individual streams
104
105   - Implement "prior-knowledge" HTTP/2 connecitons over clear text so that
106     curl can connect with HTTP/2 at once without 1.1+Upgrade.
107