The original reference Http://mp.weixin.qq.com/s/czx0AHaItrJ-c49XDboIUg HTTP is an application-layer protocol based on the TCP/IP protocol that specifies the communication format between the client and the server, using 80 ports by default
Version 1.0 request format is as follows
get/http/1.0//Request command, the protocol version must be added at the tail (http/1.0)
user-agent:mozilla/5.0 (Macintosh;intel Mac OS X 10_10_5)//Description client case
accept:*/*//Client declaration can accept data format
Accept-encoding:gzip,deflate//client shows which compression methods they can accept
Connection:keep-alive//Require the service side not to close the TCP connection, non-standard
The response format is as follows
http/1.0 OK//Protocol version status Code status description
Content-type:text/plain//Tell the client the format of the data
content-length:139099
Expires:thu,05 DEC 1997 16:00:00 GMT
last-modified:wed,5 August 1996 15:55:28 GMT
Server:apache 0.84
Content-encoding:gzip//Data compression method
Connection:keep-alive//Tell the client not to close the TCP connection, non-standard
The values of Content-type are common as follows
Text/plain
Text/html
Text/css
Image/jpeg
Image/png
Image/svg+xml
Audio/mp4
Video/mp4
Application/javascript
Application/pdf
Application/zip
Application/atom+xml
Always known as MIME type, each value includes one-level type/two-level type
Manufacturers can customize types
The MIME type can be added to the trailing parameters, as follows
Content-type:text/html;charset=utf-8//Send is the page encoding is UTF-8
The MIME type can be written in the Web page as follows
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
content-length:3456//Tell the browser the length of the response and the next response
Distinguish which response the packet belongs to, stating the length of the response
Major drawback: Each TCP connection can send only one request, and it is closed when it is sent
HTTP1.1
The introduction of persistent connections, that is, TCP connections are not closed by default, can be reused by multiple requests, after a period of inactivity, actively shut down the connection.
Canonical procedure the client sends a connection:close on the last request, explicitly telling the server to close the connection
Most browsers allow 6 persistent connections to be established at the same time
Pipeline mechanism in the same TCP connection, the client can send multiple requests simultaneously
Transfer-encoding:chunked//Indicates that the response will be made up of a variable number of data blocks
Each non-empty block of data is preceded by a 16-binary numeric representation of the block length, and the last size of 0 indicates that the response data is sent to completion
Example:
http/1.1 OK
Content-type:text/plain
Transfer-encoding:chunked
3
Con
2
Wo
0
Added the verb method: put,patch,head,options,delete
Client request header information increase host field
Host:www.example.com//Specify the domain name of the server
Cons: Data communication is carried out sequentially, if the response is particularly slow after the order is queued for waiting, this is "Team head jam"
Workaround one reduced number of requests
Method two multiple open persistent connections
Http/2
is a binary protocol, the header information and the data body are both binary, collectively referred to as frames (frame) including header information frames and data frames
Retasking: In a connection the client and the browser send multiple requests or responses at the same time, without corresponding to order one by one. (That is, the server at the same time by a A-B two requests, the first response to a request discovery process is very time-consuming, will be sent to a already processed parts, and then respond to the completion of the request, the rest of a)
All packets of each request or response are referred to as a single data stream (stream), each with a unique number, the client sends out a data flow ID uniform is odd, the server issued an even ID
The client can specify the priority of the data flow, the higher the priority, the sooner the server responds
The introduction of the header information compression mechanism (header compression), on the one hand the header information using gzip or compress compressed after sending, on the other hand, the client and the server maintain a table, all fields will exist in the table to generate an index, only send index number
Allow unsolicited proactive sending of resources to clients: Server push (server push)
Scenario: The client requests a Web page contains a lot of static resources, the server is expected to request a page after the client requests static resources, and then proactively send these static resources and Web pages to the client
Getting Started with HTTP protocol-notes