As a web developer, he uses HTTP protocol every day, but he always knows nothing about it. In this paper, refer to the HTTP rfc7230 specification, and sort out the HTTP message part.
HTTP message composition
The format of the starting line is
Start line = request line (response start line) status line
These formats are rules for parsing.
Theoretically, the key order of the header fields doesn’t matter, but the best practice is to put the control fields in front, such as the host when the request is made and the date of the response, so as to find out whether it needs to be processed as soon as possible.
Set-CookieIf the sender sends a duplicate key, the receiver will merge it. The values are separated by commas.
The protocol itself has no restrictions on each header field, but in the engineering practice, some practices have been obtained, there is no general restrictions, which is related to the specific semantics of the field. There is no standard value defined for the overall header size limit, some 4K, some 8K. The server side checks that the header header exceeds the limit value and is under security consideration and will not be ignored. It will throw 4xx error.
HostFields are required in the request header. It doesn’t matter.
|field||Request header||Response head||explain|
|Host||1||0||Tell the server which host should handle it|
|User-Agent||1||0||Although the browser type has been used poorly and is not trusted, it can be used to customize the type sometimes.|
|Accept||1||0||The body type MIME type that can be received, such as text / HTML|
|Accept-Charset||1||0||Character set that can be received|
|Accept-Encoding||1||0||Acceptable encoding format|
|Content-Type||1||1||Sent body type MIME type|
There are complete categories here
There must be a header, but the body does not have to use it.
Body is the content of the transmission. Because HTTP is an application layer protocol, in addition to data transmission, you need to define the data format for transmission. These format definitions are specified in the header.
Content-LengthThe body length of the request or response must be accompanied by this field so that the other party can easily distinguish the message boundary, that is, when the body data ends. If the body is too large, you need to calculate and transfer at the same time. You can’t know the size of the whole body until the end of the final calculation. At this time, you can use chunk transfer.
Transfer-EncodingSpecifies that the two header keys are mutually exclusive, and only one can be specified. If two are specified, the receiver takes precedence.
Transfer-EncodingField. Generally, when there is a large amount of body data, chunks are used for transmission, which is more efficient. Without length, how can we know that the data transmission is over? Through a chunk with a length of 0, the corresponding block data has no content, which means that the body content is over.
What did jetty do?
Jetty is a web container. It needs to parse HTTP request and send HTTP response. What did you do? Next analysis
Pay attention to the public account [Abbot’s temple], receive the update of the article in the first time, and start the road of technical cultivation together with the Abbot