"Computer Networks - Top-Down Approach" Refinement - 2.2.3-2.2.5

“Education is not the filling of a pail, but the lighting of a fire.” - William Butler Yeats

introduction

The importance of computer network in this subject is beyond doubt, and the black book is a textbook-level classic of this subject, so this book is one of the must-reads for computer practitioners. The author uses a column to refine the knowledge of this book and help students who want to understand this knowledge quickly lay a foundation.
In this column, the author will not strictly follow the order of the chapters, but will directly list and introduce the knowledge points to help everyone understand.
Section 1.1-1.3 Section
1.4-1.7 Section
2.1-2, Section 2

text

HTTP message

A typical HTTP request message format is as follows:
insert image description here
the first line is called the request line, and the remaining lines are called header lines.

request line

Request line includes method field, URL field, HTTP version field

  1. Method field: the actions taken by this message, including GET, POST, HEAD, DELETE, and PUT. You should be able to roughly guess the actions represented by these words based on English. GET stands for request.
  2. URL field: The stuff in this field is the object of the method field. For example, when the method is GET, what is in the URL field is the requested object.
  3. HTTP version field: what version of HTTP is used.

header line

  1. The first line specifies the host where the requested object resides
  2. The second line indicates that this connection is a non-persistent connection, that is, the connection is closed after the object is sent
  3. The third line indicates the user agent, that is, the type of browser that sent this message to the server
  4. The fourth line indicates that you want the server to return the French version of this object (if there is such a version), the default version is the English version

Entity

An entity body field can also be added after the header line, as shown in the figure:
insert image description here
the entity body field is generally used for the POST method to store data to the server.

Other methods

HEAD method: Simply send a request message, let the server respond without returning the request object, often used for debugging and tracking during development
PUT method: upload an object to the server.
DELETE method: delete the object on the server

HTTP response message

Please add a picture description
Please add a picture description
This message includes an initial status line, 6 header lines and an entity body.

Entity body and initial state line

The entity body contains the requested object.
The initial status line includes the protocol version field, status code, and corresponding status information.
Common status codes:

  1. 200 OK: everything is OK
  2. 301 Moved Permanently: The request object is not in the original URL address, and the new URL is in the Location header line of the response message
  3. 400 Bad Request: Error, the message cannot be understood by the server
  4. 404 Not Found: The requested object was not found
  5. 505 HTTP Version Not Supported: As the name implies, the server does not support the HTTP protocol version of the message

header line

We explain the parts of the request message that have not been mentioned:

  1. Date: the time when the server sent the message
  2. Server: the sending server
  3. Last-Modified: The time when the requested object was last modified
  4. Content-Length: the number of bytes of the requested object
  5. Content-Type: the type of the requested object

cookie

Cookie technology is used by the server to determine the customers who have visited. Cookie technology consists of four parts:

  1. The cookie header line in the HTTP response message
  2. The cookie header line in the HTTP request message
  3. A cookie file in the end system, which is used to save the cookies set for this client by all servers visited by this client
  4. The back-end database of the Web site, used to save all customer cookies

The operation process of cookies

insert image description here

  1. The client accesses the server for the first time
  2. The server creates an ID of 1678 as a cookie for this client
  3. The server stores this new cookie together with the customer's information in the back-end database of the Web site
  4. The client puts the received cookie in his cookie file
  5. When the customer visits the same site again, the cookie set by the site will be attached to the header line, so that the server knows that this is a customer who visited last time, and can call its information in the database

web cache

Web caches (proxy servers) reduce network latency and costs in an ingenious way. Let's use an example to illustrate:
insert image description here
when there is a cache, the steps for a client to request an object are as follows:

  1. Client requests object from cache
  2. The cache looks for this object. If so, then use the conditional GET method to be described below to confirm to the server whether the object is the latest version and selectively modify it; if not, then directly request to the server
  3. The cache sends the object to the client, and if it is a modified or newly added object, the cache stores a copy of the object for the next transmission

Conditional GET method

In order to confirm whether the stored object is the latest version, the cache will send a conditional GET method request message to the server for confirmation. This message contains a Last-Modified header line:
insert image description here
this header line contains the time when this object was last modified in the cache. After the server receives this message:

  1. The server compares this time with the time when the object was last modified in the server.
  2. If it finds that the object in the cache is already the latest version, it returns an HTTP response message without the object; if it is not the latest version, then the server stores the latest version of the object in the entity body field of the HTTP response message. send.

In this way, the cache is guaranteed to send the latest version of the object.
Please add a picture description
I am Shuang_Ai, a newcomer working hard on the road of algorithms, thank you for reading! If you think it is good, you can pay attention to it, and I will bring more and more comprehensive algorithm explanations in the future!

Guess you like

Origin blog.csdn.net/m0_72987309/article/details/130279863