HTTP learn the essence of learning

一、HTTP 1.X

1.1 length request header, body of

HTTP 1.x preceding descriptor is 24 bytes, 24 bytes is the total length, length of the header is 16 bytes (the time can be resolved, and the length of the capture Packet length), then the resulting body length (24bytes-16bytes )

 

1.2

Following the request and returns the first request header information, which is the request header to be wrapped by a newline.

Length of the request header can be determined by 16-byte data values, the request to obtain the length of the head portion of the disposable head will read the request down, then a different split line feed character string according to the header information acquisition request.

By reading the overall length of the request header length, so as to obtain the length of the body of 16bytes

二、HTTP 2.X

2.1

HTTP 2.x will go through a series of handshake or a security check, and then into the application layer (Application)

Compared with HTTP 1.X HTTP 2.X, the concept of frames. It helps to split large data packets into small packets for transmission.

HTTP 1.X, one sending a message, it is a head with a large data message body, and may request HTTP 2.X into two separate portions and portions HEADER DATA, separate transmission and separate data transmission. This helps the server receives a part of a separate section or reject.

 

2.2 long connection

Receiving a request to process data

First request, sends a request comprising a request header Message after receiving the service end, if the response will reply. Reply message also contains a Header and a body portion. type body is a combination body, which contains stream1, then there stream 2 ...... stream N.

Long connection process, if messages are returned, the process directly returns, if not, wait until the message when pushed to the client.

 

3、

From client to server, a request can be, depending on the head, a plurality of different information return. Implement a socket connection, and returns information, avoid socket constantly create and consume.

4、

In HTTP 2.X, the concept of a standard 9 bytes.

The first byte: 8 bite (0 ... 7)

Second byte: 8 bite (8 ... 15)

Third byte: 8 bite (16 ... 23)

First, two, three bytes (24 Bite) indicates the length, i.e. the maximum length is 2 to the power 24

Fourth byte: 8 bite (24 ... 31) represents a type

Followed by a unique identifier Bite 32, in front of the Flags is a (special flag), followed by some data, it is used to identify HTTP 2.0

Bite followed by 40, contains the basic definition of R and a special flag bit streams, stream identifier that uniquely identifies

The next step is carried Frame Payload Data

 

 

Published 174 original articles · won praise 115 · views 830 000 +

Guess you like

Origin blog.csdn.net/nicolelili1/article/details/104305567