awesome-interview/assets/js/505fc875.9a1cd849.js

1 line
13 KiB
JavaScript

"use strict";(self.webpackChunkjjbook=self.webpackChunkjjbook||[]).push([[334],{3905:function(t,e,n){n.d(e,{Zo:function(){return T},kt:function(){return s}});var r=n(7294);function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?o(Object(n),!0).forEach((function(e){l(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function p(t,e){if(null==t)return{};var n,r,l=function(t,e){if(null==t)return{};var n,r,l={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||(l[n]=t[n]);return l}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(r=0;r<o.length;r++)n=o[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(l[n]=t[n])}return l}var i=r.createContext({}),u=function(t){var e=r.useContext(i),n=e;return t&&(n="function"==typeof t?t(e):a(a({},e),t)),n},T=function(t){var e=u(t.components);return r.createElement(i.Provider,{value:e},t.children)},k={inlineCode:"code",wrapper:function(t){var e=t.children;return r.createElement(r.Fragment,{},e)}},c=r.forwardRef((function(t,e){var n=t.components,l=t.mdxType,o=t.originalType,i=t.parentName,T=p(t,["components","mdxType","originalType","parentName"]),c=u(n),s=l,m=c["".concat(i,".").concat(s)]||c[s]||k[s]||o;return n?r.createElement(m,a(a({ref:e},T),{},{components:n})):r.createElement(m,a({ref:e},T))}));function s(t,e){var n=arguments,l=e&&e.mdxType;if("string"==typeof t||l){var o=n.length,a=new Array(o);a[0]=c;var p={};for(var i in e)hasOwnProperty.call(e,i)&&(p[i]=e[i]);p.originalType=t,p.mdxType="string"==typeof t?t:l,a[1]=p;for(var u=2;u<o;u++)a[u]=n[u];return r.createElement.apply(null,a)}return r.createElement.apply(null,n)}c.displayName="MDXCreateElement"},8316:function(t,e,n){n.r(e),n.d(e,{frontMatter:function(){return p},contentTitle:function(){return i},metadata:function(){return u},toc:function(){return T},default:function(){return c}});var r=n(7462),l=n(3366),o=(n(7294),n(3905)),a=["components"],p={sidebar_label:"\u7f51\u7edc\uff1aHTTP2 \u548c HTTP1.1 \u7684\u5bf9\u6bd4",sidebar_position:9},i="HTTP/2 \u548c HTTP/1.1 \u7684\u5bf9\u6bd4",u={unversionedId:"book3/network-http-1-2",id:"book3/network-http-1-2",isDocsHomePage:!1,title:"HTTP/2 \u548c HTTP/1.1 \u7684\u5bf9\u6bd4",description:"\u76f8\u5173\u95ee\u9898",source:"@site/docs/book3/network-http-1-2.md",sourceDirName:"book3",slug:"/book3/network-http-1-2",permalink:"/awesome-interview/book3/network-http-1-2",tags:[],version:"current",sidebarPosition:9,frontMatter:{sidebar_label:"\u7f51\u7edc\uff1aHTTP2 \u548c HTTP1.1 \u7684\u5bf9\u6bd4",sidebar_position:9},sidebar:"tutorialSidebar",previous:{title:"\u6837\u5f0f\uff1a\u79fb\u52a8\u7aef\u81ea\u9002\u5e94\u7684\u5e38\u89c1\u624b\u6bb5",permalink:"/awesome-interview/book3/css-mobile-adaptive"},next:{title:"\u7f16\u7801\uff1a\u5c06\u5217\u8868\u8fd8\u539f\u4e3a\u6811\u72b6\u7ed3\u6784",permalink:"/awesome-interview/book3/coding-arr-to-tree"}},T=[{value:"\u76f8\u5173\u95ee\u9898",id:"\u76f8\u5173\u95ee\u9898",children:[]},{value:"\u56de\u7b54\u5173\u952e\u70b9",id:"\u56de\u7b54\u5173\u952e\u70b9",children:[]},{value:"\u77e5\u8bc6\u70b9\u6df1\u5165",id:"\u77e5\u8bc6\u70b9\u6df1\u5165",children:[{value:"1. HTTP/1.1",id:"1-http11",children:[]},{value:"2. HTTP/2",id:"2-http2",children:[]}]},{value:"\u53c2\u8003\u8d44\u6599",id:"\u53c2\u8003\u8d44\u6599",children:[]}],k={toc:T};function c(t){var e=t.components,n=(0,l.Z)(t,a);return(0,o.kt)("wrapper",(0,r.Z)({},k,n,{components:e,mdxType:"MDXLayout"}),(0,o.kt)("h1",{id:"http2-\u548c-http11-\u7684\u5bf9\u6bd4"},"HTTP/2 \u548c HTTP/1.1 \u7684\u5bf9\u6bd4"),(0,o.kt)("h2",{id:"\u76f8\u5173\u95ee\u9898"},"\u76f8\u5173\u95ee\u9898"),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"\u4e86\u89e3 HTTP/2 \u5417"),(0,o.kt)("li",{parentName:"ul"},"HTTP/1.0\u3001HTTP/1.1 \u548c HTTP/2 \u7684\u533a\u522b")),(0,o.kt)("h2",{id:"\u56de\u7b54\u5173\u952e\u70b9"},"\u56de\u7b54\u5173\u952e\u70b9"),(0,o.kt)("p",null,(0,o.kt)("inlineCode",{parentName:"p"},"\u961f\u5934\u963b\u585e")," ",(0,o.kt)("inlineCode",{parentName:"p"},"\u6301\u4e45\u8fde\u63a5")," ",(0,o.kt)("inlineCode",{parentName:"p"},"\u4e8c\u8fdb\u5236\u5206\u5e27\u5c42")," ",(0,o.kt)("inlineCode",{parentName:"p"},"\u591a\u8def\u590d\u7528")," ",(0,o.kt)("inlineCode",{parentName:"p"},"\u670d\u52a1\u7aef\u63a8\u9001")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"HTTP/1.1 \u76f8\u8f83 HTTP/1.0 \u7684\u6539\u8fdb\u548c\u4f18\u5316\uff1a")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"\u6301\u4e45\u8fde\u63a5"),(0,o.kt)("li",{parentName:"ul"},"HTTP \u7ba1\u9053\u5316"),(0,o.kt)("li",{parentName:"ul"},"\u5206\u5757\u7f16\u7801\u4f20\u8f93"),(0,o.kt)("li",{parentName:"ul"},"\u65b0\u589e Host \u5934\u5904\u7406"),(0,o.kt)("li",{parentName:"ul"},"\u66f4\u591a\u7f13\u5b58\u5904\u7406"),(0,o.kt)("li",{parentName:"ul"},"\u65b0\u589e\u66f4\u591a\u72b6\u6001\u7801")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"HTTP/1.1 \u7684\u7f3a\u70b9\uff1a")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"\u961f\u5934\u963b\u585e\uff08Head-of-line blocking\uff09"),(0,o.kt)("li",{parentName:"ul"},"\u5934\u90e8\u5197\u4f59"),(0,o.kt)("li",{parentName:"ul"},"TCP \u8fde\u63a5\u6570\u9650\u5236")),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"HTTP/2 \u7684\u4f18\u70b9\uff1a")),(0,o.kt)("ul",null,(0,o.kt)("li",{parentName:"ul"},"\u4e8c\u8fdb\u5236\u5206\u5e27\u5c42"),(0,o.kt)("li",{parentName:"ul"},"\u591a\u8def\u590d\u7528"),(0,o.kt)("li",{parentName:"ul"},"Header \u538b\u7f29"),(0,o.kt)("li",{parentName:"ul"},"\u670d\u52a1\u7aef\u63a8\u9001")),(0,o.kt)("h2",{id:"\u77e5\u8bc6\u70b9\u6df1\u5165"},"\u77e5\u8bc6\u70b9\u6df1\u5165"),(0,o.kt)("h3",{id:"1-http11"},"1. HTTP/1.1"),(0,o.kt)("h4",{id:"11-\u76f8\u8f83-http10-\u7684\u6539\u8fdb\u548c\u4f18\u5316"},"1.1 \u76f8\u8f83 HTTP/1.0 \u7684\u6539\u8fdb\u548c\u4f18\u5316"),(0,o.kt)("p",null,"HTTP/1.1 \u76f8\u6bd4\u4e8e HTTP/1.0 \u7684\u6539\u8fdb\u548c\u4f18\u5316\u4e3b\u8981\u5305\u542b\uff1a\u6301\u4e45\u8fde\u63a5\u3001HTTP \u7ba1\u9053\u5316\u8bf7\u6c42\u3001\u5206\u5757\u7f16\u7801\u4f20\u8f93\u3001\u65b0\u589e host \u5934\u5b57\u6bb5\u3001\u7f13\u5b58\u652f\u6301\u3001\u66f4\u591a\u72b6\u6001\u7801\u7b49\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u6301\u4e45\u8fde\u63a5")),(0,o.kt)("p",null,"\u5728 HTTP/1.0 \u65f6\u671f\uff0c\u6bcf\u8fdb\u884c\u4e00\u6b21 HTTP \u901a\u4fe1\uff0c\u90fd\u9700\u8981\u7ecf\u8fc7 TCP \u4e09\u6b21\u63e1\u624b\u5efa\u7acb\u8fde\u63a5\u3002\u82e5\u4e00\u4e2a\u9875\u9762\u5f15\u7528\u4e86\u591a\u4e2a\u8d44\u6e90\u6587\u4ef6\uff0c\u5c31\u4f1a\u6781\u5927\u5730\u589e\u52a0\u670d\u52a1\u5668\u8d1f\u62c5\uff0c\u62c9\u957f\u8bf7\u6c42\u65f6\u95f4\uff0c\u964d\u4f4e\u7528\u6237\u4f53\u9a8c\u3002"),(0,o.kt)("p",null,"HTTP/1.1 \u4e2d\u589e\u52a0\u4e86\u6301\u4e45\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u4e00\u6b21 TCP \u8fde\u63a5\u4e2d\u53d1\u9001\u548c\u63a5\u6536\u591a\u4e2a HTTP \u8bf7\u6c42/\u54cd\u5e94\u3002\u53ea\u8981\u6d4f\u89c8\u5668\u548c\u670d\u52a1\u5668\u6ca1\u6709\u660e\u786e\u65ad\u5f00\u8fde\u63a5\uff0c\u90a3\u4e48\u8be5 TCP \u8fde\u63a5\u4f1a\u4e00\u76f4\u4fdd\u6301\u4e0b\u53bb\u3002"),(0,o.kt)("p",null,"\u6301\u4e45\u8fde\u63a5\u5728 HTTP/1.1 \u4e2d\u9ed8\u8ba4\u5f00\u542f\uff08\u8bf7\u6c42\u5934\u4e2d\u5e26\u6709 Connection: keep-alive\uff09\uff0c\u82e5\u4e0d\u9700\u8981\u5f00\u542f\u6301\u4e45\u8fde\u63a5\uff0c\u53ef\u4ee5\u5728\u8bf7\u6c42\u5934\u4e2d\u52a0\u4e0a Connection: close\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"HTTP \u7ba1\u9053\u5316")),(0,o.kt)("p",null,"HTTP \u7ba1\u9053\u5316\u662f\u6307\u5c06\u591a\u4e2a HTTP \u8bf7\u6c42\u540c\u65f6\u53d1\u9001\u7ed9\u670d\u52a1\u5668\u7684\u6280\u672f\uff0c\u4f46\u662f\u54cd\u5e94\u5fc5\u987b\u6309\u7167\u8bf7\u6c42\u53d1\u51fa\u7684\u987a\u5e8f\u4f9d\u6b21\u8fd4\u56de\u3002"),(0,o.kt)("p",null,"\u4f46\u662f\u7531\u4e8e HTTP \u7ba1\u9053\u5316\u4ecd\u5b58\u5728\u8bf8\u591a\u95ee\u9898\uff1a"),(0,o.kt)("ol",null,(0,o.kt)("li",{parentName:"ol"},"\u7b2c\u4e00\u4e2a\u54cd\u5e94\u6162\u4ecd\u4f1a\u963b\u585e\u540e\u7eed\u54cd\u5e94"),(0,o.kt)("li",{parentName:"ol"},"\u670d\u52a1\u5668\u4e3a\u4e86\u4fdd\u8bc1\u80fd\u6309\u5e8f\u8fd4\u56de\u9700\u8981\u7f13\u5b58\u63d0\u524d\u5b8c\u6210\u7684\u54cd\u5e94\u800c\u5360\u7528\u66f4\u591a\u8d44\u6e90"),(0,o.kt)("li",{parentName:"ol"},"\u9700\u8981\u5ba2\u6237\u7aef \u3001\u4ee3\u7406\u548c\u670d\u52a1\u5668\u90fd\u652f\u6301\u7ba1\u9053\u5316")),(0,o.kt)("p",null,"\u6240\u4ee5\u76ee\u524d\u5927\u90e8\u5206\u4e3b\u6d41\u6d4f\u89c8\u5668\u9ed8\u8ba4\u5173\u95ed HTTP \u7ba1\u7ebf\u5316\u529f\u80fd\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u5206\u5757\u7f16\u7801\u4f20\u8f93")),(0,o.kt)("p",null,"\u5728 HTTP/1.1 \u534f\u8bae\u91cc\uff0c\u5141\u8bb8\u5728\u54cd\u5e94\u5934\u4e2d\u6307\u5b9a Transfer-Encoding: chunked \u6807\u8bc6\u5f53\u524d\u4e3a\u5206\u5757\u7f16\u7801\u4f20\u8f93\uff0c\u53ef\u4ee5\u5c06\u5185\u5bb9\u5b9e\u4f53\u5206\u88c5\u6210\u4e00\u4e2a\u4e2a\u5757\u8fdb\u884c\u4f20\u8f93\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u65b0\u589e Host \u5934\u5904\u7406")),(0,o.kt)("p",null,"\u5728 HTTP/1.0 \u4e2d\u8ba4\u4e3a\u6bcf\u53f0\u670d\u52a1\u5668\u90fd\u7ed1\u5b9a\u4e00\u4e2a\u552f\u4e00\u7684 IP \u5730\u5740\uff0c\u56e0\u6b64\u4e00\u53f0\u670d\u52a1\u5668\u4e5f\u65e0\u6cd5\u642d\u5efa\u591a\u4e2a Web \u7ad9\u70b9\u3002"),(0,o.kt)("p",null,"\u5728 HTTP/1.1 \u4e2d\u65b0\u589e\u4e86 host \u5b57\u6bb5\uff0c\u53ef\u4ee5\u6307\u5b9a\u8bf7\u6c42\u5c06\u8981\u53d1\u9001\u5230\u7684\u670d\u52a1\u5668\u4e3b\u673a\u540d\u548c\u7aef\u53e3\u53f7\u3002"),(0,o.kt)("h4",{id:"12-http11-\u7684\u7f3a\u70b9"},"1.2 HTTP/1.1 \u7684\u7f3a\u70b9"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u961f\u5934\u963b\u585e")),(0,o.kt)("p",null,"\u867d\u7136\u5728 HTTP1.1 \u4e2d\u589e\u52a0\u4e86\u6301\u4e45\u8fde\u63a5\uff0c\u80fd\u5728\u4e00\u6b21 TCP \u8fde\u63a5\u4e2d\u53d1\u9001\u548c\u63a5\u6536\u591a\u4e2a HTTP \u8bf7\u6c42/\u54cd\u5e94\uff0c\u4f46\u662f\u5728\u4e00\u4e2a\u7ba1\u9053\u4e2d\u540c\u4e00\u65f6\u523b\u53ea\u80fd\u5904\u7406\u4e00\u4e2a\u8bf7\u6c42\uff0c\u6240\u4ee5\u5982\u679c\u4e0a\u4e00\u4e2a\u8bf7\u6c42\u672a\u5b8c\u6210\uff0c\u540e\u7eed\u7684\u8bf7\u6c42\u90fd\u4f1a\u88ab\u963b\u585e\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u5934\u90e8\u5197\u4f59")),(0,o.kt)("p",null,"HTTP \u8bf7\u6c42\u6bcf\u6b21\u90fd\u4f1a\u5e26\u4e0a\u8bf7\u6c42\u5934\uff0c\u82e5\u6b64\u65f6 cookie \u4e5f\u643a\u5e26\u5927\u91cf\u6570\u636e\u65f6\uff0c\u5c31\u4f1a\u4f7f\u5f97\u8bf7\u6c42\u5934\u90e8\u53d8\u5f97\u81c3\u80bf\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"TCP \u8fde\u63a5\u6570\u9650\u5236")),(0,o.kt)("p",null,"\u6d4f\u89c8\u5668\u5bf9\u4e8e\u540c\u4e00\u4e2a\u57df\u540d\uff0c\u53ea\u5141\u8bb8\u540c\u65f6\u5b58\u5728\u82e5\u5e72\u4e2a TCP \u8fde\u63a5\uff08\u6839\u636e\u6d4f\u89c8\u5668\u5185\u6838\u6709\u6240\u5dee\u5f02\uff09\uff0c\u82e5\u8d85\u8fc7\u6d4f\u89c8\u5668\u6700\u5927\u8fde\u63a5\u6570\u9650\u5236\uff0c\u540e\u7eed\u8bf7\u6c42\u5c31\u4f1a\u88ab\u963b\u585e\u3002"),(0,o.kt)("h3",{id:"2-http2"},"2. HTTP/2"),(0,o.kt)("h4",{id:"21-http2-\u7684\u4f18\u70b9"},"2.1 HTTP/2 \u7684\u4f18\u70b9"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u4e8c\u8fdb\u5236\u5206\u5e27\u5c42")),(0,o.kt)("p",null,"\u5728 HTTP/1.x \u4e2d\u4f20\u8f93\u6570\u636e\u4f7f\u7528\u7684\u662f\u7eaf\u6587\u672c\u5f62\u5f0f\u7684\u62a5\u6587\uff0c\u9700\u8981\u4e0d\u65ad\u5730\u8bfb\u5165\u5b57\u8282\u76f4\u5230\u9047\u5230\u5206\u9694\u7b26\u4e3a\u6b62\u3002\u800c HTTP/2 \u5219\u662f\u91c7\u7528\u4e8c\u8fdb\u5236\u7f16\u7801\uff0c\u5c06\u8bf7\u6c42\u548c\u54cd\u5e94\u6570\u636e\u5206\u5272\u4e3a\u4e00\u4e2a\u6216\u591a\u4e2a\u7684\u4f53\u79ef\u5c0f\u7684\u5e27\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u591a\u8def\u590d\u7528")),(0,o.kt)("p",null,"HTTP/2 \u5141\u8bb8\u5728\u5355\u4e2a TCP \u8fde\u63a5\u4e0a\u5e76\u884c\u5730\u5904\u7406\u591a\u4e2a\u8bf7\u6c42\u548c\u54cd\u5e94\uff0c\u771f\u6b63\u89e3\u51b3\u4e86 HTTP/1.1 \u7684\u7ebf\u5934\u963b\u585e\u548c TCP \u8fde\u63a5\u6570\u9650\u5236\u95ee\u9898\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"Header \u538b\u7f29")),(0,o.kt)("p",null,"\u4f7f\u7528 HPACK \u7b97\u6cd5\u6765\u538b\u7f29\u5934\u90e8\u5185\u5bb9\uff0c\u5305\u4f53\u79ef\u7f29\u5c0f\uff0c\u5728\u7f51\u7edc\u4e0a\u4f20\u8f93\u53d8\u5feb\u3002"),(0,o.kt)("p",null,(0,o.kt)("strong",{parentName:"p"},"\u670d\u52a1\u7aef\u63a8\u9001")),(0,o.kt)("p",null,"\u5141\u8bb8\u670d\u52a1\u7aef\u4e3b\u52a8\u5411\u6d4f\u89c8\u5668\u63a8\u9001\u989d\u5916\u7684\u8d44\u6e90\uff0c\u4e0d\u518d\u662f\u5b8c\u5168\u88ab\u52a8\u5730\u54cd\u5e94\u8bf7\u6c42\u3002\u4f8b\u5982\u5ba2\u6237\u7aef\u8bf7\u6c42 HTML \u6587\u4ef6\u65f6\uff0c\u670d\u52a1\u7aef\u53ef\u4ee5\u540c\u65f6\u5c06 JS \u548c CSS \u6587\u4ef6\u53d1\u9001\u7ed9\u5ba2\u6237\u7aef\u3002"),(0,o.kt)("h2",{id:"\u53c2\u8003\u8d44\u6599"},"\u53c2\u8003\u8d44\u6599"),(0,o.kt)("ol",null,(0,o.kt)("li",{parentName:"ol"},(0,o.kt)("a",{parentName:"li",href:"https://httpwg.org/specs/rfc7541.html"},"HPACK: Header Compression for HTTP/2"))))}c.isMDXComponent=!0}}]);