HTTP2 & HPACK #pyfes 2013-11-30

2,766 views

Published on

introduction to HTTP2 & HPACK
based on
http2 draft-08
hpack draft-04

at pyfes 2013.11 http://connpass.com/event/4273/

Published in: Technology
  • Be the first to comment

HTTP2 & HPACK #pyfes 2013-11-30

  1. 1. HTTP2.0 & HPACK based on draft-08 2013/11/30 #pyfes
  2. 2. ● ● ● ● ● ● id: Jxck github: Jxck twitter: jxck_ about: http://jxck.io blog: http://d.hatena.ne.jp/jxck Love: music Jack
  3. 3. HTTP ? spec and status
  4. 4. History of HTTP ... 1996/ 5 1997/ 1 2009/11 ... 2011/ 9 2012/ 8 2012/11 ... 2013/ 7 ... 2013/10 2013/11 HTTP/0.9 HTTP/1.0 (RFC 1945) HTTP/1.1 (RFC 2068) SPDY/1 WebSocket(RFC 6455) HTTP/2.0 start HTTP/2.0 (draft-00) HPACK (draft-00) HPACK (draft-04) HTTP/2.0 (draft-08)
  5. 5. HTTP / 1.1 motivation version ● ● ● ● ● HTTP/0.9 ● HTTP/1.0 ● HTTP/1.1 Sharing Documents Over TCP Text Base Protocol Stateless ○ Keep-Alive ○ Pipelining
  6. 6. Req / Res on HTTP/1.1 Text Base Protocol GET /index.html HTTP/1.1 Host: example.org Accept: text/html CLIENT HTTP/1.1 200 OK Content-Type: text/html Content-Length: 35 <!DOCTYPE html> <title>hello</title> SERVER
  7. 7. HTTP ? ● Simple ○ text base, easy scaling etc ○ good for document sharing ○ but Good for Now ? ● now “Web” is ○ ○ ○ ○ Plat Form (not only document sharing) Ajax, WebSocket… tons of JS, CSS, Images... PC, Mobile, Tablet, TV, Game … ● needs ○ more speed ○ more efficiency ○ more secure
  8. 8. HTTP/2.0? history and status
  9. 9. about HTTP2 ● httpbis wg at IETF from 2012 ● motivation ○ update HTTP/1.1 ● version ○ ○ ○ ○ ○ draft-00 (copy of spdy/3) ... draft-08 (2013/11/30 current) ... RFC XXXX (2014 spring? bit.ly/130oZrZ)
  10. 10. SPDY or HTTP2.0 ? SPDY/3 http2.0-00 SPDY/4 http2.0-01 http2.0-08 SPDY/n ?? http2.0
  11. 11. specs ● working on github ! ○ https://github.com/http2/http2-spec ● draft ○ http://tools.ietf.org/wg/httpbis/draft-ietf-httpbis-http2/ ● current (2013/8/28) ○ http://tools.ietf.org/html/draft-ietf-httpbis-http2-08 ● ML ○ http://lists.w3.org/Archives/Public/ietf-http-wg/ ○ https://www.ietf.org/mailman/listinfo/http-devops
  12. 12. HTTP/2.0 draft-08 ● ● ● ● ● Multiplexing (same as spdy) Server Push (same idea as spdy) ALPN / Upgrade Binary Frames HPACK
  13. 13. Starting HTTP2.0 (1/2 step) ● “http://” ○ Upgrade Header like websocket ● “https://” ○ ALPN (application layer protocol negotiation) ○ not NPN like spdy ● Known Supported ○ prior knowledge from DNS or so ○ may immediately send http2.0 frame
  14. 14. TLS-ALPN (Application Layer protocol negotiation)
  15. 15. Starting HTTP2.0 (2/2 step) ● sending connection header ○ make sure peer supports http2.0 ○ with Magic Octets 505249202a20485454502f322e300d0a0d0a534d0d0a0d0a invalid Method PRI PRI * HTTP/2.0 rnrn SM rnrn 2 new line for parser
  16. 16. Frame Type ● ● ● ● ● ● ● ● ● ● DATA HEADERS PRIORITY RST_STREAM SETTINGS PUSH_PROMISE PING GOAWAY WINDOW_UPDATE CONTINUATION
  17. 17. HEADERS & DATA frame HEADERS(stream_id=1) + END_STREAM + END_HEADERS :method = GET :scheme = https :authority = example.org :path = /index.html accept = text/html HEADERS(stream_id=1) CLIENT - END_STREAM + END_HEADERS :status = 200 content-type = text/html content-length = 35 DATA(stream_id=1) + END_STREAM <!DOCTYPE html> <title>hello</title> SERVER
  18. 18. Server Push(1) HEADERS (stream_id=1) + END_STREAM HTTP/1.1 200 OK + END_HEADERS Content-Type: text/html :method = GET Content-Length: 123 :scheme = https {binary data} example.org :authority = :path = /index.html accept = text/html CLIENT PUSH_PROMISE (stream_id=1) + END_PUSH_PROMISE Promised-Stream-ID=2 :method = GET :scheme = https :authority = example.org :path = /a.png SERVER PUSH Request
  19. 19. Server Push(2) HEADERS CLIENT - END_STREAM + END_HEADERS :status = 200 :path = /a.png content-type = image/png content-length = 123 DATA Browser Cache (stream_id=2) (stream_id=2) + END_STREAM {binary data} PUSH Respons SERVER
  20. 20. Server Push(2) HEADERS (stream_id=1) - END_STREAM + END_HEADERS :status = 200 content-type = text/html content-length = 33 CLIENT Response SERVER DATA (stream_id=1) + END_STREAM <html> <img src=”a.png”> </html> cache hit !!
  21. 21. HPACK (header compression) ● HTTP Header ○ Text Base ○ Long Name ○ Send multiple time ● SPDY compression ○ CRIME ● HPACK ○ send diff ○ using binary
  22. 22. Static Header Table Index Header Name 1 :authority 2 :method 3 Header Value ... ... 51 refresh GET 52 retry-after :method POST 53 server 4 :path / 54 set-cookie 5 :path /index.html 55 strict-transport-security 6 :scheme http 56 transfer-encoding 7 :scheme https 57 user-agent 8 :status 200 58 vary 9 :status 500 59 via ... ... ... 60 www-authenticate ...
  23. 23. Huffman Code (Request) sym 'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o' ( 97) ( 98) ( 99) (100) (101) (102) (103) (104) (105) (106) (107) (108) (109) (110) (111) MSB |01000 |101111 |01001 |110000 |0001 |110001 |110010 |110011 |01010 |1110001 |1110010 |01011 |110100 |01100 |01101 len [5] [6] [5] [6] [4] [6] [6] [6] [5] [7] [7] [5] [6] [5] [5] hex 8 2f 9 30 1 31 32 33 a 71 72 b 34 c d LSB [5] [6] [5] [6] [4] [6] [6] [6] [5] [7] [7] [5] [6] [5] [5]
  24. 24. Header Representation ● Indexed Header Representation ● Literal Header Representation ○ Literal Header without Indexing ○ Literal Header with Incremental Indexing
  25. 25. HPACK example (1/2) 63byte -> 16byte Request Header :method: GET :scheme: http :path: / :authority: www.example.com Static Table Decoded Data 82 ADD index 2 87 ADD index 7 86 ADD index 6 04 8b db6d 883e 68d1 cb12 25ba 7f ADD key at index 4 value “www.example.com” 1 :authority 2 :method GET 3 :method POST Reference Set 4 :path / 1 :authority www.example.com 5 :path /index.html 2 :path / 6 :scheme http 3 :scheme http 7 :scheme https 4 :method GET
  26. 26. HPACK example (2/2) 87byte -> 8byte Request Header :method: GET :scheme: http :path: / :authority: www.example.com cache-control: no-cache Decoded Data 1b 86 63 65 4a 13 98 ff ADD key at index 27 value “cache-control: no-cache” Static Table 1 :authority 2 :method GET Reference Set 3 :method POST 1 cache-control no-cache 4 :path / 2 :authority www.example.com 5 :path /index.html 3 :path / 6 :scheme http 4 :scheme http 7 :scheme https 5 :method GET
  27. 27. implementations ● ● ● ● ● ● ● ● ● ● ● ● ● nghttp2 C http2-katanaC# node-http2 node.js Mozilla C++ http2-perl Perl iij-http2 node.js Akamai GhostC++ Chromium C++ Hasan's GFE C++ Twitter Java Wireshark C http2-go Go http2 Haskell see: https://github.com/http2/http2-spec/wiki/Implementations
  28. 28. Tools? Tools for dev
  29. 29. Wireshark & TCP dump
  30. 30. nghttp2 ● C implementation library ● nghttp ○ client cli tool ● nghttpd ○ file server ● nghttpdx ○ proxy web frontend of nghttp2 => http2cat
  31. 31. HTTP2Cat (https://jxck.io/labs/http2cat)
  32. 32. books ● High Performance Browser Networking ○ by Ilya Grigorik(Google) ● Translate to Japanese ? ○ http://twitter.com/turky/status/406663190768914432
  33. 33. Q & A anyone ?
  34. 34. END thanks :)

×