HTTP packets are divided into three parts: request line/status line, packet header, and packet body.
Request line: GET /home HTTP/1.1 (request method, URI, and protocol version)
Response line: HTTP/1.1 200 OK (protocol version, status code, and reason phrase)
The first field
Function: Provides the browser and server with additional information, including the size of the packet body, the language used, and authentication information
The header field information is divided into the following four types according to its functions, and the important field information is listed:
1. Generic header field
A generic header field is a header field that is used in both the request and the response.
cache-control
Cache-control is a complex field that can be used in both the request header and the response header and has different meanings.
- Public :(server) this cache resource can be used as a public resource
- Private :(server) this cache resource can only be provided to specific users
- No-cache :(guest) the cache does not accept expired resources, that is, the cache server checks with the server each time. The cache server is not allowed to cache resources.
- No-store: The cache server is not allowed to cache any part of the request.
- Max-age :(guest) if the cache time has exceeded the max-age, the cache server sends a request to the server again. Allows the cache server to process the request itself without having to issue a confirmation request to the server.
- Min-fresh: Tell the cache server not to give me any resources that expire in x seconds.
- Max-stale :(guest) tell the cache server that I can still receive requests that expire in x seconds.
- No-transform: Do not change the media type in my message body (do not compress images etc.)
- Only -if-cached:(return 504) tell the cache server not to request it again. You don’t need to ask the server to confirm the validity of the resource. If you have a cache, give it to me.
- Must -revalidate:(server) the cache server must confirm the validity of the resource with the source server, or return 504 if it cannot.
- Proxy-revalidate :(server) requires the cache server to revalidate the validity of the cache.
date
If there is no cache, Date is the time the response was generated, and if there is a cache, Date is the time the response was cached.
progma
Historical legacy field used by cache servers compatible with versions prior to HTTP1.1. program:no-cache
So to be compatible with all versions of the server:
cache-control:no-cache
program:no-cache
Transfer-Encoding
When transmitting the main body information, the main body information needs to be transformed and encoded, which is only used in block transmission coding.
Transfer-encoding: chunked
Connection
(1). Control the jump head
Connection:upgrade Tells the proxy server that forwarding does not need to be carried again
(2). Managing persistent links
The HTTP1.1 version defaults to persistent links, which are specified when the server wants to break the link
Connection:false
Prior to HTTP1.1, non-persistent links were specified by default in order to maintain persistent links
Connection:keep-alive
2. Request header field
The request header field is used to supplement information about the client when sending the request, additional information about the request, and priorities related to the response content.
Accept
Represents the type of media that the client expects the server to return. (Comma separates the type, semicolon separates the attribute, q represents the weight value)
Accept: audio/*; Q = 0.2, audio/basic
Accept-Charset
Represents the type of character set that the client expects the server to return. (Comma separates the type, semicolon separates the attribute, q represents the weight value)
Accept-Charset: utf8, gbk; Q = 0.6
Accept-Encoding
Represents the encoding compression that the client expects the server to return.
Accept-Encoding:gzip,deflate
Accept-Language
Represents the language set that the client expects the server to return.
Authorization
Informs the server of the user agent’s authentication information, and Authorization can provide certificate values or user names and passwords for specific sites that are accessible only. (For authentication between client and server)
Host
An IP address may contain multiple domain names. When sending a request, the server does not know which domain name is requested. Therefore, the Host field is required to specify the Host name of the request.
If starts with conditional requests, which are executed when the server meets the if condition, and not otherwise.
if-Match
The server accepts the request only if the if-match field is equal to the ETag value of the server resource.
if-None-Match
In contrast to if-match, requests are processed when the server has an ETag that does not Match the value of the if-none-match field. Used to get the latest data.
if-Modified-Since
The request is processed when the server resource is updated after the time specified by if-modified-since.
The value of if-modified-since is the value of last-modified, which represents the time of the last modification. If-modified-since confirms to the server that the resource has not been updated Since the last modification. If so, the server accepts the request, otherwise it does not.
if-Unmodified-Since
In contrast to if-modified-since, the server is told that the resource has not changed after the period of if-unmodified-since and the request is processed.
if-Range
if-Range:’123456′ Range:bytes=500-1000
If the server ETag matches the field value in the IF-range, the server processes the request as a partial request. If not, the new total resource is returned.
Proxy-Authorization
The same Authorization is used for authentication between clients and agents.
Range
A request to obtain part of a resource. Range can represent an interval of a Range.
Referer
Tells the server the original URI of the request
3. Response header field
The response header field is used to supplement the additional information of the response, server information, and additional requirements for the client.
Accept-Ranges
Accept-ranges :bytes tells clients that range requests can be processed
Accept-ranges: None tells clients that range requests cannot be processed
Age
Represents the age of the resource cache.
ETag
This field represents the entity id of the resource. Different resources and resource changes correspond to different ETags. This parameter is used together with if-match \ if-not-match to determine the validity of the resource cache.
Location
When the server generates a 302 redirect, this field is generally returned, indicating the redirected address.
HTTP/1.1 302 Temporary Redirect Location: https://www-temp.example.org/
WWW-Authenticate
Www-authenticate is a header that 401 Unauthorized error codes must carry when they return. The header carries a Challenge to the client and informs the client that it needs to carry the answer to the question to request the server to continue accessing the target resource. (Used for response before server and client)
Proxy-Authenticate
Same as above, for the response between proxy server and client.
Server
It is used to return server-related software information to inform the client that the current HTTP service is provided by such and such software. It can be regarded as a software advertisement.
vary
This header is used for cache control. For some cache servers, adding the Vary parameter to the request tells the cache server to use a different cache unit for the Vary parameter response. For example, if the Vary parameter is encoded, different encoded pages will have different caches. Vary can have more than one value and will have different caches as long as any one value is different.
Vary: Accept-Encoding,Accept-Language
4. Entity header field
The entity head field is the header in the packet body used to supplement information about the packet content, such as update time and packet content.
Allow
Indicates that the server informs the client of the HTTP methods it supports.
Allow: GET, HEAD, PUT
Content-Encoding
Tells the client how the server encodes the content portion of the entity.
Content-Language
Tells the client the language set used by the server for the entity content portion.
Content-Length
Tell the client the length of the content of the server-side entity.
Content-Location
Tell the client which URI the server-side entity content comes from.
Content-Range
Tell the client the scope of the entity content returned by the server.
Content-Type
Tell the client the media type of the entity content returned by the server.
Expires
Indicates the time when the resource expires. The cache server will use this field as the standard. If the time exceeds this field, it will send a request to the server again. Otherwise, it will use the cache.
When the Expires time equals the Date time, the resource is invalidated.
When a max-age is specified in cache-control, the expires field is ignored in favor of max-age.
last-Modified
The time when the resource was last modified.