Preface: There are two reasons for writing this article;

  • 1: Frankly speaking, I am not very familiar with HTTP. I only know that I have not studied the commonly used things field by field.
  • 2: When looking up information or reading books, many nouns sound very difficult, and I can’t understand their meaning, or understand ambiguous (PS: sometimes I really think it is a machine copy ~~~ haha).

1. HTTP Headers composition

  • General Header (Common header (request response will have))
  • Request Header (Request header)
  • Response Header (Response header)
  • Entity Header (Solid head (for body))

So let’s draw a picture

  • The request message

  • The response message

So let's take a look at each of these. Okay

1.1 the General Header

  • What is it: a Header used by both request and response packets

  • What fields are included? And field description:

    Cache-control (a number of instructions are supported to Control the Cache policy, which will not be extended here) Connection function 1: specify the content to be removed during forwarding. 2: Manage persistent connections. The default connection for HTTP/1.1 is persistent. At this point, the client sends requests continuously over a persistent connection. When the server side wants to explicitly disconnect, specify the value of the Connection header field as Close. The default connection for HTTP versions prior to HTTP/1.1 was non-persistent. In this case, if you want to maintain a continuous Connection over the old VERSION of HTTP, you need to set the value of the Connection header field to keep-alive Upgrade, which is used to check whether HTTP and other protocols can communicate with a later version. The parameter value can be used to specify information about a completely different communication protocol such as TLS VIA proxy server. When a message passes through a proxy or gateway, it adds information about the server to the Via header field before forwarding it (which I personally think is important). This is a retry-after version of HTTP/1.0's Response Header. The user is often warned of cache-related issues. Transfor-encoding The transport Encoding of the body of the message (in HTTP/1.1 this field is only valid for chunking transport Encoding) Trailer will specify in advance which fields are logged after the body of the message. Pragma is a field left over from previous VERSIONS of HTTP/1.1. Date is defined only as backward compatibility with HTTP/1.0 to indicate the time when HTTP packets are created. (GMT)Copy the code

1.2 Request Header Parsing

  • What is it: the Header that the client uses to make a request to the server

  • What fields are included? And field description:

    Accept Specifies the media types that the user can process. You can specify more than one accept-charset at a time to tell the server what character set the client wants accept-encoding Message compression policy (such as gzip Deflate) Accept-language Desired Language type (CN, EN ....) From user's email address Host Server where the requested resource resides (Host is the only header field that must be included in the request in HTTP/1.1 specifications) Return Precondition 200, otherwise return 412 Feed Failed if-Modified-since To compare the update time of the resource 304 Not Modified if-none-match Comparison entity flag (opposite to if-match) if-range If the resource is Not updated Request for the scope of a resource if-unmodified-since Compares the update time of the resource (as opposed to if-modified-since) max-forward server Minus 1 for the forward value of max-forward before forwarding the request to the next server. When the server receives a request for max-forward value of 0, no forwarding is performed, Instead, it directly returns the server that responds to the proxy-authorization Proxy server's request for the client's authentication information in the Range Range request (used during breakpoint continuation). A 206 Partial Content response is returned after the request is processed. When the range request cannot be processed, a response with status code 200 OK and all resources are returned. The Referer tells the server the URI of the original resource requested. The TE header field tells the server how the client can process the response and its relative priority. It is similar to the accept-encoding function of the header field, but it is used to transmit the Encoding. In addition to specifying the transport code, the header field TE can also specify how to block the transport code along with the Trailer field. When you use block transport, you just assign the Trailers to the value of the field and the User-agent will communicate information like the browser and User Agent name that created the request to the server. When a web crawler initiates a request, it is possible to add the email address of the crawler author to the field. Also, if the request goes through a proxy, the proxy server name is likely to be added in the middleCopy the code
  • Find an example of a request header to get a feel for what it looks like

    • Note :(the following example may not have some fields (such as the above TE Range), which may be related to the scene, so we will not go into the details here)
      GET/HTTP/1.1 Host: hackr.jp proxy-connection: keep-alive Cache-control: max-age=0 proxy-authorization: Basic MTYzMjc5NjgxMUAxODE0MDQyOmJhNjhiNjBmNmZkMWI5NzQ0ZGQ4ZDFmOWJkYWJjODhj Upgrade-Insecure-Requests: 1 User-Agent: Mozilla / 5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml; Q = 0.9, image/avif, image/webp image/apng, * / *; Q = 0.8, application/signed - exchange; v=b3; Q =0.9 Accept-encoding: gzip, deflate Accept-language: zh-cn,zh; Q =0.9 if-none-match: "25E-4d2C3145df440-gzip" if-modified-since: Tue, 08 Jan 2013 08:53:29 GMTCopy the code

1.3 Response Header Parsing

  • What is it: the Header used by the server in response to the packet sent to the client

  • What fields are included? And field description:

    Accept-ranges whether to Accept range requests; There are two types of field values that can be specified, bytes for range requests and None for range requests. Age tells the client how long ago the source server created the response. The unit is second. Parameter Description Value ETag Matching information of the resource. Is a way to uniquely identify a resource as a string. The server assigns each resource an ETag value of Location to redirect the client to the specified URI. This field provides the URI for the Redirection along with the 3xx: Redirection response. Proxy-authenticate Authenticate information about the client by the Proxy server. The authentication information requested by the proxy server is sent to the client. It is similar to HTTP access authentication between client and server, except that the authentication takes place between client and proxy. In the authentication between client and server, it has the same function as the header field WWW-authorization. Retry-after Specifies the time required to initiate a request again; Tell the client how long it should take to send the request again. This parameter is used with the 503 Service Unavailable response or 3XX Redirect response. The value can be the date and time (Wed, 04 Jul 2012 06:34:24 GMT) or the number of seconds after the response is created. Server Installation information about the HTTP Server. Tells the client about the HTTP server application installed on the current server. Not only is the software application name marked on the server, but it may include the version number and the optional Vary proxy server cache that is enabled at installation time; When a proxy server receives a request for a resource specified by the Vary header field, if the accept-language field is the same, it responds directly from the cache with www-Authenticate to the client. Used for HTTP access authentication. It tells the client to request the authentication scheme specified by a URI (Basic or Digest) and a challenge with a parameter prompt. Status code 401 Unauthorized. In the response, be sure to include the header field wwW-Authenticate.Copy the code
  • Find an example of a response header to get a feel for what it looks like

    • Note: some fields in this example may not be present (e.g., Vary retry-after, etc.) and may be context-dependent.
      HTTP/1.1 200 OK Date: Wed, 25 Aug 2021 02:01:10 GMT Last-Modified: Tue, 08 Jan 2013 08:53:29 GMT ETag: "25e-4d2c3145df440-gzip" Accept-Ranges: bytes Content-Encoding: gzip Content-Length: 379 Content-Type: Text/HTML Connection: keep-aliveCopy the code

1.4 Entity Header Parsing

  • What is: the Header used for the entity (body) of the request message and the response message

  • What fields are included? And field description:

    Allow HTTP methods supported by resources Content-Encoding Body Applicable Encoding method Content-Language Body natural Language Content-Length Body size (unit: Bytes) Content-location replaces the packet digest of the URI content-MD5 body of the corresponding resource; Md5 Format Content-range Body location Range Content-Type Body Media Type Expires Body Expiration date and time Last-Modified date and time of the Last modification of the resourceCopy the code

I have to say that this book written by a Japanese who lives a good life is quite good, and I recommend all students to read this book.

Reference: Illustrated HTTP