Share
Embed
Transcript
37 slides
-
Very beginning of HTTP/2 2018-07-06 / #web_kaiwai @ariaki4dev What’s Hypertext
Transfer Protocol ? -
HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2 - 1991 年に登場 - GET メソッド
- ステータスコードなし - ヘッダなし - Content-Type が指定できないので HTML のみ転送可 HTTP Histories -
HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2 - 1996 年に登場 ( RFC1945 )
- HEAD / POST メソッドが追加された - PUT / DELETE は正式仕様ではなく参考仕様 - ステータスコードが追加された - ヘッダが追加された - HTML 以外の転送にも対応 - クッキーはまだない HTTP Histories -
HTTP/1.1 HTTP/2 GET /index.html HTTP/1.0 User-Agent: NCSA_Mosaic/2.0 (Windows 3.1) Request
HTTP/0.9 HTTP/1.0 200 OK Date: Fri, 06 Jul 2018 19:00:00 GMT Server: CERN/3.0 libwww/2.17 Content-Type: text/html <HTML>HELLO WORLD</HTML> Response HTTP Histories -
HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2 - 1999 年に登場 ( RFC2068 )
- PUT / DELETE / OPTIONS / TRACE / CONNECT メソッドが追加された - 1台の HTTPd で複数ドメインに対応した ( Host ) - コネクションの再利用に対応した ( Keep-Alive ) - Chunked レスポンスに対応した - 言語 / タイプ / エンコーディングのネゴシエーションに対応した - HTTP パイプラインに対応した - 1つの TCP 接続で複数 HTTP リクエストを応答を待たずに送信できる HTTP Histories -
GET /index.html HTTP/1.1 Host: ariaki.info Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Accept-Encoding: gzip, deflate,
br Accept-Language: ja,en-US;q=0.9,en;q=0.8 Cache-Control: max-age=0 HTTP/2 Request HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP Histories -
HTTP/1.1 200 OK Date: Fri, 06 Jul 2018 19:00:00 GMT
Server: Apache Content-Type: text/html; charset=UTF-8 Cache-Control: private, max-age=0 Expires: -1 Connection: Keep-Alive <HTML>HELLO WORLD</HTML> HTTP/2 Response HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP Histories -
HTTP/0.9 HTTP/1.0 HTTP/1.1 HTTP/2 - 2015 年に登場 ( RFC7540 )
- HTTP/1.1 との後方互換性を維持 - 多くの新機能や改善 HTTP Histories 詳細は次のトピック -
- ネゴシエーション方法として以下をサポート - h2c ( 非暗号通信 ) - Upgrade :
初回は HTTP/1.1 接続し、Upgrade ヘッダで対応を通知 - Direct : クライアントから直接 HTTP/2 接続を指定 - h2 ( 暗号通信 ) - ALPN : TLS/1.2+ 拡張を使用した暗号化接続 ( Application-Layer Protocol Negotiation ) - NPN : TLS/1.2+ 拡張を使用した暗号化接続 ( Next Protocol Negotiation ) 概要 Negotiation -
h2c - Upgrade HTTP/1.1 101 Switching Protocols Connection: Upgrade Upgrade:
h2c : Response GET / HTTP/1.1 Host: ariaki.info Connection: Upgrade, HTTP2-Settings Upgrade: h2c HTTP2-Settings: <<BASE64 ENCODED BINARY>> Request Negotiation -
h2c - Direct <<BASE64 ENCODED BINARY>> Response PRI * HTTP/2.0
SM Request Negotiation -
h2 - ALPN ClientHello Handshake Message ServerHello ALPN Extention 通信プロトコル候補
ALPN Extention 通信プロトコル決定 Negotiation 暗号化 -
暗号化 Negotiation h2 - NPN ClientHello Handshake Message ServerHello NPN
Extention 通信プロトコル候補 NPN Extention 通信プロトコル決定 -
Binary Frame TYPE FRAME DESCRIPTION 0 DATA リクエスト/レスポンスの本文 1 HEADERS
リクエスト/レスポンスのヘッダ情報 2 PRIORITY ストリーム優先順位(※クライアントのみ送信可) 3 RST_STREAM ストリーム終了(※エラー時など) 4 SETTINGS 接続設定の変更 5 PUSH_PROMISE サーバプッシュ予告(※サーバのみ送信可) 6 PING 接続の生存状態を確認 7 GOAWAY 接続終了(※エラー時など) 8 WINDOW_UPDATE ウインドウサイズ変更 9 CONTINUATION サイズの大きい HEADERS / PUSH_PROMISE フレーム断片 -
リクエストヘッダの基本形 Header Compression GET /index.html HTTP/1.1 Host: ariaki.info : HTTP/1.1
:method GET :path / :scheme https :authority ariaki.info Accept */* : HTTP/2 -
リクエストヘッダの送信方法 Header Compression - ヘッダ情報はキャッシュ ( Reference Set ) し、2
回目以降は差分送信 - ヘッダ名は別途管理 ( Table ) し、2 回目以降は Index 指定 - Table 最大長は SETTINGS_MAX_HEADER_LIST_SIZE で指定 - 超過した場合は FIFO で削除 - ヘッダは Binary 形式 ( Binary Optimized Header Encoding ) - HPACK 圧縮 -
リクエストヘッダ テーブル Header Compression - Index, Name, Value を持つテーブル構造 -
静的テーブル - 使用頻度の高いヘッダ - Index ( 1 - 61 ) が規定されている - 動的テーブル - その他のヘッダデータ - Index ( 62 - ) を自動採番する - 2回目以降は Index を使って指定する -
静的テーブル ( 一部抜粋 ) Header Compression +-------+-----------------------------+---------------+ | Index |
Header Name | Header Value | +-------+-----------------------------+---------------+ | 1 | :authority | | | 2 | :method | GET | | 3 | :method | POST | | 4 | :path | / | | 5 | :path | /index.html | | 6 | :scheme | http | | 7 | :scheme | https | | 8 | :status | 200 | | 9 | :status | 204 | | 10 | :status | 206 | | 11 | :status | 304 | | 12 | :status | 400 | | 13 | :status | 404 | | 14 | :status | 500 | | 15 | accept-charset | | +-------+-----------------------------+---------------+ | Index | Header Name | Header Value | +-------+-----------------------------+---------------+ | 16 | accept-encoding | gzip, deflate | | 17 | accept-language | | | 18 | accept-ranges | | | 19 | accept | | | 20 | access-control-allow-origin | | | 21 | age | | | 22 | allow | | | 23 | authorization | | | 24 | cache-control | | | 25 | content-disposition | | | 26 | content-encoding | | | 27 | content-language | | | 28 | content-length | | | 29 | content-location | | | 30 | content-range | | https://tools.ietf.org/html/draft-ietf-httpbis-header-compression-12#appendix-A -
テーブル指定 Header Compression +-------+-----------------------------+---------------+ | Index | Header Name |
Header Value | +-------+-----------------------------+---------------+ | 1 | :authority | | | 2 | :method | GET | | 4 | :path | / | | 7 | :scheme | https | :method GET :path / :scheme https :authority ariaki.info x-test-header DEBUG : 2 GET 4 / 7 https 1 ariaki.info x-test-header DEBUG ( ※次回以降は 62 を指定 ) : -
概要 Multi Plexing - HTTP/1.1 - セッション毎に 1 リクエストずつ処理 -
同一ドメインに対して同時 6 セッション / Google Chrome - 複数ドメインに対して同時 2 セッション / HTTP 推奨仕様 - サーバはリクエストの順番通りに返却しなければならない - HTTP/2 - 同一セッション内で同時に複数 ( 100+ ) リクエスト可 - リクエスト時にレスポンス優先順位を設定可 -
Multi Plexing HTTP/1.1 HTTP/2 (1) GET /index.html (2) GET /app.css
(3) GET /app.js (1) GET /index.html (2) GET /app.css (3) GET /app.js (4) GET /logo.png (4) GET /logo.png 1セッション内で 複数リクエスト 複数セッションを 平行リクエスト * Response all -
HTTP/2 の課題 Problems - Head of Line Blocking 問題 -
レスポンス完了まで後続のリクエストを受け付けられない - 小さなレスポンス圧縮によるサイドチャネル攻撃 - CRIME / BREACH 等 - Server Push: キャッシュ済データを送信する問題 - 103 Early Hints 等で改善中 - Priority: 優先度を喋らないクライアントに対する応答方法がサーバ実装任せ -
その他 Otherwise - WEB 界隈はセキュリティ強化がホットな状況 - TLS 1.3 : draft
28 が IETF 正式勧告 ( OpenSSL 等が対応済 ) - DoH : いくつかの Public DNS が対応開始 - QUIC : まだ 1 年以上かかりそう -
OSS Server Products Compatibility - Apache HTTP Server 2.4.17+ (
mod_http2 ) - nginx 1.9.5+ - OpenSSL 1.0.2+ - NodeJS 9+ ( node-http2 ) - Apache Tomcat 8.5.32+ ( and more )