HTTP message
HTTP message is composed by:
-
start line
-
header
-
CRLF (empty line)
-
body
Start line
Request line
It is composed by:
Method URL Version
GET / HTTP/1.1
Response line
Version code reason
HTTP/1.1 200 OK
or
HTTP/1.1 404 Not Found
Header
Header contains the info in key-value format. There are some rule.
- Key is insensible to the case.
Hostis equal tohost. _and\sis not allowed in the key.-is ok.- There is no space before
:. - The order of header is meaningless.
fields
There are 4 classes of header.
-
common fields
It exists in all kinds of http message.
Data: the creation time of http message.
-
request fields
-
Host: It's only the required request fields inHTTP/1.1. -
User-Agent: the client who sends the request.
-
-
response fields
Server:
-
body fields:
It's a part of the common fields.
Content-Length: the length of thebody. If this header is not set, the body is sent separately. We need to addTransfer-Encoding:chuncked.