Summary
As a web developer, all users Http protocol, but always little knowledge every day. This article See Http RFC7230 specification, combed http message part.
http message construction
start-line: basic information of the start line, or in response to the description request
* (header-field CRLF): header
CRLF
[Message-body]: message body, the actual data transmission
header
Start Line
Format is the start line
start-line = request-line (request start line) / (the response start line) status-line
header header
These formats are rules for parsing
Sequence
theoretically key sequence header fields does not matter, it is best practice in front of the control field, such as when the requested Host, Date response, whether this can be found as soon as possible.
Was repeated
except that Set-Cookie
the key, all else fails, if the sender sent duplicate key, which the recipient will merge, a comma-separated values.
Field Limits
agreement itself does not limit for each header field, some of the practices but had come in engineering practice, there is no general restrictions, and related fields specific semantics. Overall header size limit does not define the standard value, some 4K, some 8K. end server header check to the head more than the limit value, for security reasons, will not be ignored. But it will throw 4XX error.
Only Host
field is necessary with the request header, the other does not matter.
Field | Request header | Response header | Explanation |
---|---|---|---|
Host | 1 | 0 | Tells the server which should be handled by the host |
User-Agent | 1 | 0 | Identifies the browser type, though has been used up, not very credible, but sometimes you can use to customize the type of |
Accept | 1 | 0 | Body type can receive mime type, such as text / html |
Accept-Charset | 1 | 0 | You can receive character set |
Accept-Encoding | 1 | 0 | Encoding formats may be received |
Accept-Language | 1 | 0 | You can receive multiple languages |
Content-Type | 1 | 1 | Sent body type mime type |
Content-Encoding | 1 | 1 | Send coding |
Content-Language | 1 | 1 | Send Language |
Here are the complete classification
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
body
header is a must have, but the body will not have to use.
body is the content transmission. Http is because the application layer protocol, so in addition to data transmission, also need to define the data format for transmission. The format definition specified in the header. Content-Length
Request or response length of the body, it is necessary to bring the field, so that the other side can easily distinguish the packet boundary, i.e. when the end data Body. If the Body is too big, you need to calculate the side edge transmission until the last end of the calculation is impossible to know the size of the entire Body, this time you can use the chunk transmission through Transfer-Encoding
specified that the two are mutually exclusive header key can only specify one, if It specifies two receiving end priority Transfer-Encoding
field. The body is usually relatively long time data are transmitted using the chunk, more efficient. The length is not, know how the data transmission end, by a length of the chunk 0, no segmentation data corresponding to the content, content to indicate the end of the body.
What did jetty
jetty is a web container needs to resolve Http Request, sent Http Response. What did the analysis of specific next time
No. [public concern] abbot of the monastery, the first time to receive the updated article, beginning with the way technology practice of the abbot
reference
https://tools.ietf.org/pdf/rfc7230.pdf
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers