As a web developer , Every day users Http agreement , But I always know a little . See Http RFC7230 standard , Combed http Message part .
start-line: Start line , Basic information describing the request or response
*( header-field CRLF ): head
[ message-body ]: news body, Data actually transmitted
The format of the starting line is
start-line = request-line( Request start line ）/（ Response start line ）status-line
These formats are rules , Used to parse
In theory, the key Order doesn't matter , But the best practice is to put the control field first , For example, when requesting Host, Responsive Date, In this way, we can find out whether we need to deal with it as soon as possible .
Set-Cookie This key, Nothing else , If the sender sends a duplicate key, The receiver will merge it , Values are separated by commas .
The protocol itself has no restrictions on each header field , But in the engineering practice, we have got some practices , There are no general restrictions , Related to the specific semantics of the field . Holistic header The size limit does not define a standard value , There are some 4K, There are some 8K.server End check to header Head over limit , On safety grounds , Don't ignore . But will throw 4XX error .
Host Fields are required in the request header , Nothing else .
|Field||Request header||Response head||explain|
|Host||1||0||Tell the server which host should handle|
|User-Agent||1||0||Identify browser type , Although it has been used up , Not very believable , But sometimes it can be used to customize the type|
|Accept||1||0||Acceptable body type mime type, such as text/html|
|Accept-Charset||1||0||Character set that can be received|
|Accept-Encoding||1||0||Acceptable encoding format|
|Accept-Language||1||0||Multiple languages that can be received|
|Content-Type||1||1||Sent body type mime type|
There is a complete classification here
header It's necessary , however body You don't have to use .
body It's the content of the transmission . because Http It's the application layer protocol , So in addition to transmitting data , You also need to define the data format of the transfer . These formats are defined in header It is specified in .
Content-Length Requesting or responding to body length , You have to bring this field , So that the other side can easily distinguish the message boundary , That is to say Body When does the data end . If Body Too big , Need to calculate while transmitting , You can't know the whole thing until the end of the final calculation Body The size of , It can be used at this time chunk transmission , adopt
Transfer-Encoding Appoint , these two items. header key They are mutually exclusive. , Only one... Can be specified , If two are specified , The receiver takes priority
Transfer-Encoding Field . Usually body When there are more data , All use chunk To transmit , High efficiency . period length, How to know that the data transmission is over , Through a length of 0 Of chunk, The corresponding block data has no content , To express body End of content .
jetty yes web Containers , Need analysis Http Request, send out Http Response. What did you do next time
Official account 【 Abbot's temple 】, The first time to receive an update of the article , Start the road of technical cultivation with the abbot