This document provides an introduction to HTTP/2, including:
- HTTP/1.x has drawbacks like occupying one TCP connection per request and slow start-up times.
- HTTP/2 aims to address these by being binary based, multiplexed, compressed and allowing server push.
- It grew out of SPDY and was standardized by the IETF, maintaining the HTTP paradigm while improving performance.
5. Intro to HTTP/2
Why HTTP/2
HTTP/1.x drawbacks nowadays
Workarounds for speeding up HTTP/1.1
Goal of HTTP/2
Features of HTTP/2
Demo
6. The IETF HTTP Working Group
HTTP/2 is a replacement for how HTTP is
expressed “on the wire.” It is not a ground-up
rewrite of the protocol
7. HTTP/1.x Drawbacks
Occupy a TCP connection per request
TCP 3-way handshake
Slow-start of TCP flow control
HTTP Pipelining vs. Head-Of-Line Blocking
(HOL)
8. Headers are sent with
every request…
. Accept-Ranges:bytes
. Access-Control-Allow-Origin:*
. Age:147613
. Cache-Control:max-age=31536000, public
. Content-Encoding:gzip
. Content-Length:23993
. Content-Type:text/css
. Date:Sat, 03 Jun 2017 07:13:47 GMT
. Expires:Fri, 01 Jun 2018 14:13:33 GMT
. Last-Modified:Sat, 01 Jan 2000 00:00:00 GMT
. Server:GitHub.com
. Timing-Allow-Origin:*
. Vary:Accept-Encoding
. Via:1.1 varnish
. X-Cache:HIT
. X-Cache-Hits:39503
. X-Fastly-Request-ID:4e6f64d3b645f29d9f71564cafa495c30445eca2
. X-GitHub-Request-Id:F9FC:22433:1761B1:1D1A91:5930210D
. X-Served-By:cache-itm7427-ITM
11. Concatenation
A.K.A Bundle
Combining multiple javascript files into a bigger one
instead of making multiple requests separately
Inconvenient to developer
Redundant download due to a small change
12. Domain Sharding
Splitting resources across multiple domains to
improve page load time
Avg 40 TCP connections for a page according
to http://httparchive.org/
13.
14. HTTP Pipelining
Pipeline multiple HTTP requests into a TCP connection to server
without waiting each response
Default disabled by browsers like Chrome and Firefox
15. Intro to HTTP/2
Why HTTP/2
HTTP/1.x drawbacks nowadays
Workarounds for speeding up HTTP/1.1
Goal of HTTP/2
Features of HTTP/2
Demo
16. HTTP/2
IETF and HTTPbis workgroup
“bis” is a suffix of name used to describe
upgrade of protocol
From SPDY/3 draft -> HTTP/2 draft-00
17. Boundaries for HTTP/2
Maintain HTTP/1.x paradigm
http:// and https:// URLs cannot be changed
Be able to proxy HTTP/1 request to HTTP/2
Then proxies must be able to map HTTP/2 features to
HTTP/1.x clients 1-1 mapping
Remove or reduce optional parts or protocol
No more minor version
18. HTTP/2 for Existing URI
schemes
HTTP/1.1 has defined a way to do upgrade - header
One more Round-Trip (SPDY team wouldn’t accept the penalty)
SPDY achieve this by only implementing SPDY over TLS (no
extra protocol)
NPN (Next Protocol Negotiation)
Server list out all supported protocols for client to choose
19. HTTP/2 vs. TLS
SPDY depends on TLS and HTTP/2 bases on SPDY
BUT TLS is optional in HTTP/2
Chrome and Firefox implement it based on TLS (leaders say so)
long-running debate about whether dictate cipher suites for using TLS
NPN -> ALPN (Application Layer Protocol Negotiation)
Main difference: who decide protocol negotiation?
ALPN: client sends out a prioritized list to server and server decide which one to be
used
NPN: server sends out a list for client to choose
20. Intro to HTTP/2
Why HTTP/2
HTTP/1.x drawbacks nowadays
Workarounds for speeding up HTTP/1.1
History from SPDY to HTTP/2
Goal of HTTP/2
Features of HTTP/2
Demo
25. Multiplexed
The ability to break down HTTP message into
independent frames, interleave them, and
reassemble them
https://http2.akamai.com/demo
see Chrome Dev Tool
29. Header Compression
Using HPACK compression format to reduce overhead
Static and Dynamic table
Allows the transmitted headers to be encoded via Huffman code
Literal values are (optionally) encoded with a static Huffman code
previously seen headers - transferring indexed value
https://http2.github.io/http2-spec/compression.html
32. Flow Control
TCP flow control is not granular enough - doesn’t provide
app-level to regulate individual stream
It is directional
It is credit-based
It cannot be disabled
It is hop-by-hop, not end-to-end
33. CURL vs. HTTP/2
Nghttp2
Similar use to HTTP/1.x
Negotiation
Using upgrade header to support HTTP2
Using TLS library - beware of OpenSSL version
—http2 option of CLI
curl_easy_setopt - SURLOPT_HTTP_VERSION
CURL_HTTP_VERSION_2
Multiplexing
最初的HTTP 1.1規範提到一個客戶端最多只能對同一主機建立兩個TCP連接。因此,為了不和規範衝突,一些聰明的網站使用了新的主機名,這樣的話,用戶就能和網站建立更多的連接,從而降低載入時間。後來,兩個接的限制被取消了,現在的客戶端可以輕鬆地和每個主機建立6-8個連接。但很多網站還是會使用此技術來提高connection數量
YouTube splits images and script resources across two domains: i.ytimg.com and s.ytimg.com. i.ytimg.com contains icons, logos, thumbnails, avatars, and other visual elements while s.ytimg.com contains JavaScript, CSS, favicons, sprite sheets, and objects related to website optimization and analytics.
frame payload size是根據receiver advertises in the SETTINGS_MAX_FRAME_SIZE setting
冷知識:在 HTTP/1.1 定義了四種解析訊息的方式,在 HTTP/2 只需要一種
• Frame: The smallest unit of communication in HTTP/2, each containing a frame header, which at a minimum identifies the stream to which the frame belongs.
• Message: A complete sequence of frames that map to a logical request or response message.
• Stream: A bidirectional flow of bytes within an established connection, which may carry one or more messages.
在HPACK壓縮時會有 static and dynamic 兩種table ,static 為predefined 且比較common的header field list
dynamic table一開始則是空的,然後會在decompress後更新table
所以整個request的size會因為沒看過的header被huffman壓縮,然後再用index去static or dynamic table 去查表得到 value