HTTP request response process

(1) Request response process

        In our daily life, we use browsers every day. Are you curious, what happens when we enter the URL of a website? Let's explore it through an example. Let's assume that the visited URL address is

http://www.baiduu.com/s/1754896, when we enter the URL, the following operations will be performed inside the browser.

  • The DNS server will first analyze the domain name , just like the domain name www.baiduu.com, our browser must not be able to find the location of Baidu’s server and establish a connection only by the domain name, so the DNS server will first analyze the domain name and find The ip address corresponding to the domain name mapping

DNS domain name resolution process

First, the browser will find the corresponding ip address according to the domain name DNS lookup process is as follows

  • First of all, the browser will first search its own DNS cache (the cache time is very short, only about one minute, and can only accommodate about 1000 caches ), to see if there is an entry corresponding to the domain name in its own cache, and it has not expired. If it exists and has not expired, the parsing ends here
  • System cache: If the corresponding entry is not found in the browser's own cache, the browser will search the operating system's own DNS cache, and if it is found and has not expired, the search will stop and the parsing will end here
  • Router cache: If the system cache is not found, a query request will be sent to the router.
  • ISP (Internet Service Provider) DNS cache: If it is not found in the routing cache, the last thing to check is the DNS server cached by the ISP

Then let's go back to the HTTP request flow

  • After DNS analysis, we also know the ip address corresponding to the domain name, and then the HTTP client process initiates a TCP connection request to www.baiduu.com on port 80 ( 80 is the default port of HTTP ) and then passes three handshakes To establish a connection, there will be a socket connection between the client and the server
  • The HTTP client sends an HTTP request message to the server through its socket . The message contains the resource path /s/1754896
  • The HTTP server accepts the message through its socket, analyzes the request, and retrieves the object http://www.baiduu.com/s/1754896 from its memory (RAM or disk), and then retrieves the The object is encapsulated, encapsulated into the HTTP response message, and sent to the client through the socket
  • The HTTP server immediately notifies TCP to disconnect the TCP connection. In fact, it needs to wait until the client receives the response message before disconnecting the TCP connection.
  • After HTTP receives the response message, the TCP connection will be closed. The message extracted by the HTTP client from the response is an HTML response file, and checks the HTML file, and then loops through other internal objects in the message
  • After the check is completed, the HTTP client will present the corresponding resource to the user through the display

Guess you like

Origin blog.csdn.net/asdasd121312dasd/article/details/127992227