Http的1.0
Question 1: Short connection
http is based on the Tcp protocol, because it is a short connection, each http; connection and disconnection will correspond to the three-way Tcp handshake, slow-start connection and four waved disconnection. (It can be solved by setting Connection: keep-alive)
Problem 2: Blocking
The number of simultaneous requests initiated by the client is fixed, and if there are too many requests, it will be queued and blocked.
Http 1.1 optimization
Optimization 1: Long connection
A Tcp connection channel can parallel multiple http requests and closes. But the server still processes the order of client requests. So the server will still block.
Optimization 2: Cache optimization
Cache processing, in HTTP1.0, the If-Modified-Since and Expires in the header are mainly used as the criteria for caching judgment, HTTP1.1 introduces more cache control strategies such as Entity tag, If-Unmodified-Since, If-Match, If-None-Match and more optional cache headers are available to control the cache strategy.
Optimization 3: Management of error notifications.
Added 24 error status response codes in HTTP1.1. For example, 409 (Conflict) indicates that the requested resource conflicts with the current state of the resource; 410 (Gone) indicates that a resource on the server is permanently deleted
Optimization 4: New request method
PUT: request the server to store a resource;
DELETE: request the server to delete the identified resource;
OPTIONS: request to query the performance of the server, or query the options and requirements related to the resource;
TRACE: request the server to send back the received request information, mainly for testing Or diagnosis;
CONNECT: reserved for future use
Optimization 5: Host optimization
Added Host optimization, through different hosts can support service one IP corresponds to multiple virtual Host hosts.
Optimization 6: Resumable upload optimization
The range header field is introduced, which allows only a certain part of the resource to be requested, that is, the return code is 206 (Partial Content), which facilitates the free choice of developers in order to make full use of bandwidth and connections.
Http2.0 optimization
Optimization 1: Fully multiplexed
The client and server can initiate or reply in parallel to avoid the blockage caused by serialization.
Optimization 2: Message compression
More compression algorithms and optimized transmission of repeated fields such as cookies
Optimization 3: Binary framing
Added binary framing layer. Between the http layer and tcp, the frame can be disordered and assembled at the other end.
Optimization 4: Server push
One request to the client, multiple responses
Request examples and analysis
// 请求
GET / HTTP/1.1
Host:xxx.xxxx.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.10) Gecko/2016042316 Firefox/3.0.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
If-Modified-Since: Mon, 25 May 2016 03:19:18 GMT
//响应
HTTP/1.1 200 OK
Cache-Control: private, max-age=30
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Expires: Mon, 25 May 2016 03:20:33 GMT
Last-Modified: Mon, 25 May 2016 03:20:03 GMT
Vary: Accept-Encoding
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 25 May 2016 03:20:02 GMT
Content-Length: 12173
Status code meaning
HTTP 1.1 status codes and their meaning
The status code consists of three digits. The first digit defines the response category, and there are five possible values:
1xx: Indication message-indicates that the request has been received, continue processing
2xx: Success-indicates that the request has been successfully received, understood, and accepted
3xx: Redirect-further action must be taken to complete the request
4xx: client error-the request has a syntax error or the request cannot be fulfilled
5xx: server-side error-the server failed to fulfill a legitimate request
Reference:
https://www.jianshu.com/p/52d86558ca57
https://www.debugger.wiki/article/html/1565502376358922
https://juejin.im/entry/6844903489596833800
https://blog.csdn.net /zhglance/article/details/76162176
https://github.com/Advanced-Frontend/Daily-Interview-Question/issues/232