HTTP message headers
HTTP packet format is as follows:
报文 neck |
---|
A blank line (CR + LF) |
The message body |
Requests and responses are HTTP protocol packet header must contain HTTP. Header content client and the server requests and responses are processed to provide the required information.
In the request, HTTP packet consists of a method, the URI, HTTP version, HTTP header fields and other parts
in response, HTTP packet by the HTTP version, status codes (numbers and reason phrase), HTTP header field 3 parts.
HTTP header field
HTTP header fields convey important information
HTTP header field by field names and field values header portion constituted by a colon ":" separator
首部字段名:字段值
For example, in HTTP to the Content-Type header field to indicate the type of object packets body
Content-Type: text / html
field value corresponding to a single HTTP header field may have multiple values, as shown below.
keep-Alive:timeout=15,max=100
4 kinds of HTTP header field type
HTTP header field is divided into the following four types depending on the application.
- Common header field (General Header Fields)
the request packet and response packet header are both used. - Header field of the request (Request Header Fields)
transmission request used when the header packet from the client to the server. Supplemented with additional content requested, client information, in response to the content-related information such as priority. - Response header field (Response Header Fields)
returned to the client using the response header packet from the server. Complements the additional content of the response, the client will be required to attach additional content information. - Entity header field (Entity Header Fields)
for the request packet and response packet header entity partially used. Supplementary information and resources related to the entity content update time.
End-to-end header and Hop-by-hop header
HTTP header field is defined as a non-caching proxies and caching behavior of the agent, divided into two types.
- The first end portion (End-to-end Header)
points in this category will be forwarded to a header request / response corresponding to the final target received, and must be stored in a response generated by the cache, it must be forwarded otherwise specified. - By-hop header (Hop-by-hop Header)
points in this category header only valid for a single transponder, due to cache or by proxy rather than forward. Version HTTP / 1.1 and later, if you want to use hop-by-hop header, must provide the Connection header field.
Here are HTTP / 1.1 in the by-hop header fields: - Connection
- Keep-Alive
- Proxy-Authenticate
- Proxy-Authorization
- Trailer
- TO
- Transfer-Encoding
- Upgrade
In addition to these eight header field, all other fields belong to the head-end.
HTTP / 1.1 header field general
General header field refers to the request packet and response packet headers will be used by both sides.
Cache-Control
By specifying Cache-Control header field of instruction, be able to operate the working mechanism of the cache.
Cache-Control directives:
- Indicate whether the cache instruction:
public instruction: When specifying the use of public instruction, make it clear that other users can also take advantage of the cache
private instruction: When a designated private instruction, only respond to specific user as an object, this behavior and public instruction Instead
no-cache directive: no-cache directive purpose is to prevent the return of expired resource from the cache. - Cache control target executable instructions:
no-store instruction: When using no-store instruction, suggesting request (and the corresponding response) contain confidential information or response. Relative to the no-cache, no-store is really not cached. - Cache period specified instruction and certification of
the same functions as s-maxage maxage instruction and instruction, s-maxage Directive applies only to public cache server for multiple users.
max-age command: When the cache is determined that the time value is smaller than the cache resources specified time value, the client would receive buffer resources.
min-fresh instructions: min-fresh claims cache server returns at least over a specified time has not cache resources.
max-stale instructions: using the max-stale cached resource may refer to expire as usual even if the reception.
only-if-cached instructions: Use only-if-cached directive means that the client will be required to return only in the case of a cache server local cache of the target resource.
must-revalidate directive: agent verifies that the upcoming return of the currently cached response is still valid to the source server again.
proxy-revalidate instruction: requires all cache server receives the request before the client returns a response with the instruction, the cache must validate again.
no-transform instructions: using the predetermined instruction, whether the media type in the request or response, the cache can not change the entity body. This prevents caching or proxy compress images and other similar operations.
Connection
Connection header field includes the following two functions:
- Control is no longer forwarded to the header field agent
- Management persistent connections
Control header field agent no longer forwarded:
Connection:不再转发的首部字段名
Management persistent connections:
Connection:close
HTTP / 1.1 version default connections are persistent connection. To this end, the client request is sent continuously on a persistent connection. When the server wants to disconnect explicitly, the specified Connection header field value Close
Connection:Keep-Alive
1.1 HTTP connection before the default version of HTTP / are non-persistent connection. For this reason, if you want to maintain a constant connection on the older version of the HTTP protocol, you need to specify the Connection header field value Keep-Alive.
Date
Date header field indicate the date and time HTTP packet
Date :Tue, 03 Jul 2012 04:40:59 GMT
Pragma
As this instruction is backward compatible with HTTP / 1.0 is defined
Pragma:no-cache
The header field belonging to the common header field, but only in the request sent by the client. The client will ask all the intermediate server does not return cached resource
Trailer
Trailer header field will be stated in advance in the main body of the message header fields which are recorded. The header field may be applied when HTTP / 1.1 version chunked transfer encoding.
...
Transfer-Encoding:chunked
Trailer: Expires
...(报文主体)...
0
Expires:Tue,28 Sep 2004 23:59:59 GMT
In the above example, the header field specifies Trailer Expires value, (after deblocking length 0) Expires header field appears after the message body
Transfer -Encoding
Transfer-Encoding header field defines the coding mode to transmit the packet body is used.
Upgrade
Upgrade header field for detecting whether the HTTP protocol, and other protocols may be used to communicate a higher version, which can be used to specify a parameter value different communication protocols.
Via
Via header field is used to track the requests between the client and the server and the transmission path response message.
Packets pass through proxy or gateway, the server will first additional information in the Via header field, and then forwarded.
Via header field is not only used to track packet forwarding, but also to avoid the occurrence of the request of the loop. So you must attach the content header fields when passing proxy.
Request packet:
GET / HTTP/1.1
After the proxy server:
GET / HTTP/1.1
Via: 1.0 gw.hackr.jp(Squid/3.1)
Warning
1.1 Warning HTTP / header from the header portion (Retry-After) Response HTTP / 1.0 evolution over. The first part will usually inform the user of some cache-related issues warning
format of the header as follows:
Warning:[警告码][警告的主机:端口号]"[警告内容]"([日期时间])
HTTP / 1.1 defines seven warning, a warning code as follows:
Warning code | Warnings | Explanation |
---|---|---|
110 | Response is stale (a response has expired) | Agent returns expired resources |
111 | Revalidation failed (re-authentication fails) | Failure (reasons server can not be reached, etc.) and then verify that the agent resource availability |
112 | Disconnection operation (disconnected operation) | Agent and the Internet connection was intentionally cut off |
113 | Heuristic expiration (tentative date) | Use of more than 24 hours response (greater than 24 hours in the case of setting the cache valid time) |
199 | Miscellaneous warning (Miscellaneous warning) | Any warnings |
214 | Transformation applied (using a conversion) | When the agent performs certain encoding or processing of the content media type, etc. |
299 | Miscellaneous persistent warning (lasting Miscellaneous warning) | Any warnings |