HTTP 2.0 鍘熺悊璇︾粏鍒嗘瀽
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HTTP 2.0 鍘熺悊璇︾粏鍒嗘瀽相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%91%bd%e4%bb%a4' title='鍛戒护'>鍛戒护
浣曚簨 涔卞簭 ora 澶氫釜 streams value _id 寤惰繜
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%91%bd%e4%bb%a4' title='鍛戒护'>鍛戒护
浣曚簨 涔卞簭 ora 澶氫釜 streams value _id 寤惰繜
HTTP 2.0鏄湪SPDY锛圓n experimental protocol for a faster web, The Chromium Projects锛夊熀纭€涓婂舰鎴愮殑涓嬩竴浠d簰鑱旂綉閫氫俊鍗忚銆侶TTP/2 鐨勭洰鐨勬槸閫氳繃鏀寔璇锋眰涓庡搷搴旂殑澶氳矾澶嶇敤鏉ヨ緝灏戝欢杩燂紝閫氳繃鍘嬬缉HTTPS棣栭儴瀛楁灏嗗崗璁紑閿€闄嶄綆锛屽悓鏃跺鍔犺姹備紭鍏堢骇鍜屾湇鍔″櫒绔帹閫佺殑鏀寔銆?nbsp;
鏈枃鐩殑鏄涔燞TTP 2.0鐨勫師鐞嗗苟鐮旂┒鍏堕€氫俊鐨勮缁嗙粏鑺傘€傚ぇ閮ㄥ垎鐭ヨ瘑鐐规簮浜庛€奧eb鎬ц兘鏉冨▉鎸囧崡銆嬨€?/p>
1. 浜岃繘鍒跺垎甯у眰
浜岃繘鍒跺垎甯у眰锛屾槸HTTP 2.0鎬ц兘澧炲己鐨勬牳蹇冦€?/span> HTTP 2.0閫氫俊鐨勬渶灏忓崟浣嶏紝鍖呮嫭甯ч閮ㄣ€佹祦鏍囪瘑绗︺€佷紭鍏堝€煎拰甯у噣鑽风瓑銆?nbsp; 娑堟伅鏄寚閫昏緫涓婄殑HTTP娑堟伅锛堣姹?鍝嶅簲锛夈€備竴绯诲垪鏁版嵁甯х粍鎴愪簡涓€涓畬鏁寸殑娑堟伅銆傛瘮濡備竴绯诲垪DATA甯у拰涓€涓狧EADERS甯х粍鎴愪簡璇锋眰娑堟伅銆?/p>
娴佹槸杩炴帴涓殑涓€涓櫄鎷熶俊閬擄紝鍙互鎵胯浇鍙屽悜娑堟伅浼犺緭銆傛瘡涓祦鏈夊敮涓€鏁存暟鏍囪瘑绗︺€備负浜嗛槻姝袱绔祦ID鍐茬獊锛屽鎴风鍙戣捣鐨勬祦鍏锋湁濂囨暟ID锛屾湇鍔″櫒绔彂璧风殑娴佸叿鏈夊伓鏁癐D銆?nbsp; 鍩轰簬浜岃繘鍒跺垎甯у眰锛孒TTP 2.0鍙互鍦ㄥ叡浜玊CP杩炴帴鐨勫熀纭€涓婏紝鍚屾椂鍙戦€佽姹傚拰鍝嶅簲銆侶TTP娑堟伅琚垎瑙d负鐙珛鐨勫抚锛岃€屼笉鐮村潖娑堟伅鏈韩鐨勮涔夛紝浜ら敊鍙戦€佸嚭鍘伙紝鏈€鍚庡湪鍙︿竴绔牴鎹祦ID鍜岄閮ㄥ皢瀹冧滑閲嶆柊缁勫悎璧锋潵銆?nbsp; 娴佸彲浠ュ甫鏈変竴涓?1bit鐨勪紭鍏堢骇锛?/p>
瀹㈡埛绔槑纭寚瀹氫紭鍏堢骇锛屾湇鍔$鍙互鏍规嵁杩欎釜浼樺厛绾т綔涓轰緷鎹氦浜掓暟鎹紝姣斿瀹㈡埛绔紭鍏堢骇璁剧疆涓?css>.js>.jpg锛堝叿浣撳彲鍙傝銆婇珮鎬ц兘缃戠珯寤鸿鎸囧崡銆嬶級锛?鏈嶅姟绔寜浼樺厛绾ц繑鍥炵粨鏋滄湁鍒╀簬楂樻晥鍒╃敤搴曞眰杩炴帴锛屾彁楂樼敤鎴蜂綋楠屻€?nbsp; HTTP 2.0澧炲姞浜嗘湇鍔$鎺ㄩ€佸姛鑳斤紝鏈嶅姟绔彲浠ユ牴鎹鎴风鐨勮姹傦紝鎻愬墠杩斿洖澶氫釜鍝嶅簲锛屾帹閫侀澶栫殑璧勬簮缁欏鎴风銆傚涓嬪浘鎵€绀猴紝瀹㈡埛绔姹俿tream 1锛?page.html銆傛湇鍔$鍦ㄨ繑鍥瀞tream 1娑堟伅鐨勫悓鏃舵帹閫佷簡stream 2锛?script.js锛夊拰stream 4锛?style.css锛夈€?nbsp; HTTP 1.x姣忎竴娆¢€氫俊锛堣姹?鍝嶅簲锛夐兘浼氭惡甯﹂閮ㄤ俊鎭敤浜庢弿杩拌祫婧愬睘鎬с€侶TTP 2.0鍦ㄥ鎴风鍜屾湇鍔$涔嬮棿浣跨敤鈥滈閮ㄨ〃鈥濇潵璺熻釜鍜屽瓨鍌ㄤ箣鍓嶅彂閫佺殑閿?鍊煎銆傞閮ㄨ〃鍦ㄨ繛鎺ヨ繃绋嬩腑濮嬬粓瀛樺湪锛屾柊澧炵殑閿?鍊煎浼氭洿鏂板埌琛ㄥ熬锛屽洜姝わ紝涓嶉渶瑕佹瘡娆¢€氫俊閮介渶瑕佸啀鎼哄甫棣栭儴銆?nbsp; 鑰冭檻涓€涓棶棰橈紝瀹㈡埛绔浣曠煡閬撴湇鍔$鏄惁鏀寔HTTP 2.0锛熸槸鍚︽敮鎸佸浜岃繘鍒跺垎甯у眰鐨勭紪鐮佸拰瑙g爜锛熸墍浠ワ紝鍦ㄤ袱绔娇鐢℉TTP 2.0閫氫俊涔嬪墠锛屽繀鐒跺瓨鍦?span style="color: #ff1493">鍗忚鍗忓晢 鏀寔HTTP 2.0鐨勬祻瑙堝櫒鍙互鍦═LS浼氳瘽灞傝嚜鍙戝畬鎴愬拰鏈嶅姟绔殑鍗忚鍗忓晢浠ョ‘瀹氭槸鍚︿娇鐢℉TTP 2.0閫氫俊銆傚叾鍘熺悊鏄疶LS 1.2涓紩鍏ヤ簡鎵╁睍瀛楁锛屼互鍏佽鍗忚鐨勬墿灞曪紝鍏朵腑ALPN鍗忚锛圓pplication Layer Protocol Negotiation, 搴旂敤灞傚崗璁崗鍟? 鍓嶈韩鏄疦PN锛夌敤浜庡鎴风鍜屾湇鍔$鐨勫崗璁崗鍟嗚繃绋嬨€?nbsp; 鐒惰€岋紝HTTP 2.0涓€瀹氭槸HTTPS锛圱LS 1.2锛夌殑鐗规潈鍚楋紵 TCP杩炴帴寤虹珛锛?nbsp; 鏄笉鏄惎鐢℉TTP 2.0鍚庢€ц兘蹇呯劧鎻愬崌浜嗭紵浠讳綍浜嬫儏閮戒笉鏄粷瀵圭殑锛岃櫧鐒舵€讳綋鑰岃█鎬ц兘鑲畾鏄兘鎻愬崌鐨勩€?nbsp; 銆奧eb鎬ц兘鏉冨▉鎸囧崡銆?nbsp;
HTTP 1.x鍦ㄥ簲鐢ㄥ眰浠ョ函鏂囨湰鐨勫舰寮忚繘琛岄€氫俊锛岃€孒TTP 2.0灏嗘墍鏈夌殑浼犺緭淇℃伅鍒嗗壊涓烘洿灏忕殑娑堟伅鍜屽抚锛屽苟瀵瑰畠浠噰鐢ㄤ簩杩涘埗鏍煎紡缂栫爜銆傝繖鏍凤紝瀹㈡埛绔拰鏈嶅姟绔兘闇€瑕佸紩鍏ユ柊鐨勪簩杩涘埗缂栫爜鍜岃В鐮佺殑鏈哄埗銆?nbsp;
濡備笅鍥炬墍绀猴紝HTTP 2.0骞舵病鏈夋敼鍙楬TTP 1.x鐨勮涔夛紝鍙槸鍦ㄥ簲鐢ㄥ眰浣跨敤浜岃繘鍒跺垎甯ф柟寮忎紶杈撱€?nbsp;
1.1 甯э紙frame锛?/span>
1.2 娑堟伅锛坢essage锛?/span>
1.3 娴侊紙stream锛?/span>
鎵€鏈塇TTP 2. 0 閫氫俊閮藉湪涓€涓猅CP杩炴帴涓婂畬鎴愶紝 杩欎釜杩炴帴鍙互鎵胯浇浠绘剰鏁伴噺鐨勫弻鍚戞暟鎹祦Stream銆?鐩稿簲鍦帮紝 姣忎釜鏁版嵁娴佷互 娑堟伅鐨勫舰寮忓彂閫侊紝 鑰屾秷鎭敱涓€ 鎴栧涓抚缁勬垚锛?nbsp;杩欎簺甯у彲浠ヤ贡搴忓彂閫侊紝 鐒跺悗鏍规嵁姣忎釜甯ч閮ㄧ殑娴佹爣璇嗙閲嶆柊缁勮銆?/span>
鍦ㄤ竴涓猅CP杩炴帴涓婂畬鎴愩€?/p>
2. 澶氳矾澶嶇敤鍏变韩杩炴帴
鎴戜滑鏉ュ姣斾笅HTTP 1.x鍜孒TTP 2.0锛屽亣璁句笉鑰冭檻1.x鐨刾ipeline鏈哄埗锛屽弻鏂瑰洓灞傞兘鏄竴涓猅CP杩炴帴銆傚鎴风鍚戞湇鍔″害鍙戣捣涓変釜鍥剧墖璇锋眰/image1.jpg锛?image2.jpg锛?image3.jpg銆?nbsp;
HTTP 1.x鍙戣捣璇锋眰鏄覆琛岀殑锛宨mage1杩斿洖鍚庢墠鑳藉啀鍙戣捣image2锛宨mage2杩斿洖鍚庢墠鑳藉啀鍙戣捣image3銆?nbsp;
3. 璇锋眰浼樺厛绾?/span>
鐒惰€岋紝涔熶笉鑳借繃鍒嗚糠淇¤姹備紭鍏堢骇锛屼粛鐒惰娉ㄦ剰浠ヤ笅闂锛?/p>
4. 鏈嶅姟绔帹閫?/span>
mod_http2
鑳藉寮€鍚?nbsp;H2Push on
鏈嶅姟绔帹閫丳ush銆侼ginx鐨?code>ngx_http_v2_module杩樹笉鏀寔鏈嶅姟绔疨ush銆?/li>
1 Apache mod_headers example
2 <Location /index.html>
3 Header add Link "</css/site.css>;rel=preload"
4 Header add Link "</images/logo.jpg>;rel=preload"
5 </Location>
5. 棣栭儴鍘嬬缉
6. 涓€涓畬鏁寸殑HTTP 2.0閫氫俊杩囩▼
6.1 鍩轰簬ALPN鐨勫崗鍟嗚繃绋?/span>
鏈嶅姟绔娇鐢ˋLPN锛岀洃鍚?43绔彛榛樿鎻愰珮HTTP 1.1锛屽苟鍏佽鍗忓晢鍏朵粬鍗忚锛屾瘮濡係PDY鍜孒TTP 2.0銆?nbsp;
姣斿锛屽鎴风鍦═LS鎻℃墜Client Hello闃舵琛ㄦ槑鑷韩鏀寔HTTP 2.0
6.2 鍩轰簬HTTP鐨勫崗鍟嗚繃绋?/span>
褰撶劧涓嶆槸锛屽鎴风浣跨敤HTTP涔熷彲浠ュ紑鍚疕TTP 2.0閫氫俊銆傚彧涓嶈繃鍥犱负HTTP 1. 0鍜孒TTP 2. 0閮戒娇鐢ㄥ悓涓€涓?绔彛锛?0锛夛紝 鍙堟病鏈夋湇鍔″櫒鏄惁鏀寔HTTP 2. 0鐨勫叾浠栦换浣?淇℃伅锛屾鏃?瀹㈡埛绔彧鑳戒娇鐢℉TTP Upgrade鏈哄埗锛圤kHttp, nghttp2绛夌粍浠跺潎鍙疄鐜帮紝涔熷彲浠ヨ嚜宸辩紪鐮佸畬鎴愶級閫氳繃鍗忚皟纭畾閫傚綋鐨勫崗璁細 1 HTTP Upgrade request
2 GET / HTTP/1.1
3 host: nghttp2.org
4 connection: Upgrade, HTTP2-Settings
5 upgrade: h2c /*鍙戣捣甯︽湁HTTP2.0 Upgrade澶撮儴鐨勮姹?/span>*/
6 http2-settings: AAMAAABkAAQAAP__ /*瀹㈡埛绔疭ETTINGS鍑€鑽?/span>*/
7 user-agent: nghttp2/1.9.0-DEV
8
9 HTTP Upgrade response
10 HTTP/1.1 101 Switching Protocols /*鏈嶅姟绔悓鎰忓崌绾у埌HTTP 2.0*/
11 Connection: Upgrade
12 Upgrade: h2c
13
14 HTTP Upgrade success /*鍗忓晢瀹屾垚*/
6.3 瀹屾暣閫氫俊杩囩▼
42072: HTTP2_SESSION
1 42072: HTTP2_SESSION
2 textlink.simba.taobao.com:443 (PROXY 10.19.110.55:8080)
3 Start Time: 2017-04-05 11:39:11.459
4
5 t=370225 [st= 0] +HTTP2_SESSION [dt=32475+]
6 --> host = "textlink.simba.taobao.com:443"
7 --> proxy = "PROXY 10.19.110.55:8080"
8 t=370225 [st= 0] HTTP2_SESSION_INITIALIZED
9 --> protocol = "h2"
10 --> source_dependency = 42027 (PROXY_CLIENT_SOCKET_WRAPPER)
11 t=370225 [st= 0] HTTP2_SESSION_SEND_SETTINGS
12 --> settings = ["[id:3 flags:0 value:1000]","[id:4 flags:0 value:6291456]","[id:1 flags:0 value:65536]"]
13 t=370225 [st= 0] HTTP2_STREAM_UPDATE_RECV_WINDOW
14 --> delta = 15663105
15 --> window_size = 15728640
16 t=370225 [st= 0] HTTP2_SESSION_SENT_WINDOW_UPDATE_FRAME
17 --> delta = 15663105
18 --> stream_id = 0
19 t=370225 [st= 0] HTTP2_SESSION_SEND_HEADERS
20 --> exclusive = true
21 --> fin = true
22 --> has_priority = true
23 --> :method: GET
24 :authority: textlink.simba.taobao.com
25 :scheme: https
26 :path: /?name=tbhs&cna=IAj9EOy3fngCAXBQ5kJ9yusH&nn=&count=13&pid=430266_1006&_ksTS=1491363551394_94&callback=jsonp95
27 user-agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
28 accept: */*
29 referer: https://www.taobao.com/
30 accept-encoding: gzip, deflate, sdch, br
31 accept-language: zh-CN,zh;q=0.8
32 cookie: [382 bytes were stripped]
33 --> parent_stream_id = 0
34 --> stream_id = 1
35 --> weight = 147
36 t=370256 [st= 31] HTTP2_SESSION_RECV_SETTINGS
37 --> host = "textlink.simba.taobao.com:443"
38 t=370256 [st= 31] HTTP2_SESSION_RECV_SETTING
39 --> flags = 0
40 --> id = 3
41 --> value = 128
42 t=370256 [st= 31] HTTP2_SESSION_UPDATE_STREAMS_SEND_WINDOW_SIZE
43 --> delta_window_size = 2147418112
44 t=370256 [st= 31] HTTP2_SESSION_RECV_SETTING
45 --> flags = 0
46 --> id = 4
47 --> value = 2147483647
48 t=370256 [st= 31] HTTP2_SESSION_RECV_SETTING
49 --> flags = 0
50 --> id = 5
51 --> value = 16777215
52 t=370256 [st= 31] HTTP2_SESSION_RECEIVED_WINDOW_UPDATE_FRAME
53 --> delta = 2147418112
54 --> stream_id = 0
55 t=370256 [st= 31] HTTP2_SESSION_UPDATE_SEND_WINDOW
56 --> delta = 2147418112
57 --> window_size = 2147483647
58 t=370261 [st= 36] HTTP2_SESSION_RECV_HEADERS
59 --> fin = false
60 --> :status: 200
61 date: Wed, 05 Apr 2017 03:39:11 GMT
62 content-type: text/html; charset=ISO-8859-1
63 vary: Accept-Encoding
64 server: Tengine
65 expires: Wed, 05 Apr 2017 03:39:11 GMT
66 cache-control: max-age=0
67 strict-transport-security: max-age=0
68 timing-allow-origin: *
69 content-encoding: gzip
70 --> stream_id = 1
71 t=370261 [st= 36] HTTP2_SESSION_RECV_DATA
72 --> fin = false
73 --> size = 58
74 --> stream_id = 1
75 t=370261 [st= 36] HTTP2_SESSION_UPDATE_RECV_WINDOW
76 --> delta = -58
77 --> window_size = 15728582
78 t=370261 [st= 36] HTTP2_SESSION_RECV_DATA
79 --> fin = true
80 --> size = 0
81 --> stream_id = 1
82 t=370295 [st= 70] HTTP2_STREAM_UPDATE_RECV_WINDOW
83 --> delta = 58
84 --> window_size = 15728640
85 t=402700 [st=32475]
7. HTTP 2.0鎬ц兘鐡堕
鎴戞兂HTTP 2.0浼氬甫鏉ユ柊鐨勬€ц兘鐡堕銆傚洜涓虹幇鍦ㄦ墍鏈夌殑鍘嬪姏闆嗕腑鍦ㄥ簳灞備竴涓猅CP杩炴帴涔嬩笂锛孴CP寰堝彲鑳藉氨鏄笅涓€涓€ц兘鐡堕锛屾瘮濡俆CP鍒嗙粍鐨勯槦棣栭樆濉為棶棰橈紝鍗曚釜TCP packet涓㈠け瀵艰嚧鏁翠釜杩炴帴闃诲锛屾棤娉曢€冮伩锛屾鏃舵墍鏈夋秷鎭兘浼氬彈鍒板奖鍝嶃€傛湭鏉ワ紝鏈嶅姟鍣ㄧ閽堝HTTP 2.0涓嬬殑TCP閰嶇疆浼樺寲鑷冲叧閲嶈锛屾湁鏈轰細鎴戜滑鍐嶈窡杩涜杩般€?/p>
鍙傝€冩枃鐚?/span>
銆婁娇鐢?nghttp2 璋冭瘯 HTTP/2 娴侀噺銆?nbsp;https://imququ.com/post/intro-to-nghttp2.html
以上是关于HTTP 2.0 鍘熺悊璇︾粏鍒嗘瀽的主要内容,如果未能解决你的问题,请参考以下文章