ArcBlock's Technical Learning Series Presents: Intro to HTTP/2.
You may not know that your browser supports HTTP/2 long times ago. What exactly is HTTP/2? What's the difference between HTTP/2 and HTTP? Why do we even need HTTP2/? What can we do with HTTP/2's new feature? This talk is all about HTTP/2, also we will demonstrate how to write a simple HTTP/2 client in 33 lines of code.
HTTP/2早在2015年就被互联网工程任务小组制定为标准,我们用的浏览器其实早就悄悄支持HTTP/2了。HTTP/2到底比HTTP/1.1好在哪里?关于HTTP/2我需要知道什么?听说HTTP/3快要出了现在才讲HTTP/2是不是有点晚?这篇讲座将解答您的这些问题。另外我们也会现场演示如何用33行代码写一个最简单的HTTP/2客户端。"
1. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 1/36
Intro to HTTP/2
Brought to you by Boshan Sun
1
2. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 2/36
History of HTTP
• HTTP/0.9, 1991
• HTTP/1.0, 1996, RFC 1945
• HTTP/1.1, 1999, RFC 2616, RFC 7230-7235
• HTTP/2, 2015, RFC 7540/7541
Related protocols
• Gopher, 1991
• SPDY, 2012
2
3. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 3/36
HTTP/1.1
client <----------------------> server
GET / HTTP/1.1 HTTP/1.1 200 OK
Host: example.com Content-Length: 1270
<!doctype html>
<html>
...
</html>
3
4. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 4/36
HTTP/1.1
➜ telnet example.com 80
Trying 93.184.216.34...
Connected to example.com.
Escape character is '^]'.
GET / HTTP/1.1
Host: example.com
HTTP/1.1 200 OK
Content-Length: 1270
<!doctype html>
<html>
...
</html>
4
5. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 5/36
Problems of HTTP/1.1
• TCP is not fully utilized
• head of line blocking
• too many request to render even for one page
5
6. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 6/36
Problems of HTTP/1.1
client server
| GET / |
| -----------------------------> |
| 200 OK |
| <----------------------------- |
| |
| GET /favicon |
| -----------------------------> |
| 200 OK |
| <----------------------------- |
| |
| GET /index.js |
| -----------------------------> |
| 200 OK |
| <----------------------------- |
| |
| ... |
| |
| GET /title.png |
| -----------------------------> |
| 200 OK |
| <----------------------------- |
6
7. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 7/36
Workarounds
• spriting: use a large image
• inlining: put image inline
• concatenation: put few js in one
• sharding: connect to multiple servers
7
8. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 8/36
HTTP/2 design goal
• support url http:// & https://
• support proxy from http 1.x to http2
• no minor version number
8
9. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 9/36
HTTP/2
• RFC 7540 - HTTP version 2
• RFC 7541 - HPACK: Header Compression for HTTP/2
9
10. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 10/36
HTTP/2 features
• one TCP connection
• binary protocol
• multiplexing
• flow control and prioritization
• header compression
• server push
10
11. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 11/36
Upgrade to HTTP/2
• Upgrade to https URI
• Application Layer Protocol Negotiation(ALPN)
• A connection preface
PRI * HTTP/2.0
SM
11
25. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 25/36
Literal Header Field
• Literal Header Field with Incremental Indexing
• Literal Header Field without Indexing
• Literal Header Field Never Indexed
25
26. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 26/36
Dynamic Table
+-------+-----------------------------+---------------+
| Index | Header Name | Header Value |
+-------+-----------------------------+---------------+
+-------+-----------------------------+---------------+
:method: GET
:scheme: http
:path: /
:authority: example.com
+-------+-----------------------------+---------------+
| Index | Header Name | Header Value |
+-------+-----------------------------+---------------+
| 62 | :authority | example.com |
+-------+-----------------------------+---------------+
:method: GET
:scheme: http
:path: /
:authority: example.com
cache-control: no-cache
+-------+-----------------------------+---------------+
| Index | Header Name | Header Value |
+-------+-----------------------------+---------------+
| 62 | cache-control | no-cache |
| 63 | :authority | example.com |
26
27. 12/18/2018 Intro to HTTP/2
http://127.0.0.1:8888/backend/abb7-http2.html 27/36
Literal Header Field with Incremental Indexing
indexed name
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 1 | Index (6+) |
+---+---+-----------------------+
| H | Value Length (7+) |
+---+---------------------------+
| Value String (Length octets) |
+-------------------------------+
new name
0 1 2 3 4 5 6 7
+---+---+---+---+---+---+---+---+
| 0 | 1 | 0 |
+---+---+-----------------------+
| H | Name Length (7+) |
+---+---------------------------+
| Name String (Length octets) |
+---+---------------------------+
| H | Value Length (7+) |
+---+---------------------------+
| Value String (Length octets) |
+-------------------------------+
27