What happens in the middle of an HTTP request

When we from the browser with a string of domain name, the first client URL information, through the DNS domain name, to establish a Tcp connection (network layer down, from the application layer to eventually become the physical signal to the server), the server receives the request, will handle the request and returns a response, the browser parses rendering the page, Tcp disconnect

1 profile

A seemingly simple process, but contains a lot of knowledge. When the user enters the domain name in the browser and the Web page loads, there are a lot of things that happen that require us to understand the basics of the Web and Web applications.

2 process

  • After you enter a URL, the client obtains the URL and performs DNS resolution
  • Then find the corresponding service IP port to access the reverse proxy server (without this step)
  • Access the corresponding Web server
  • Browser render page

3 Detailed introduction

  1. So let’s start with the URL

  2. Browser parsing

    Such as URL:www.github.com/z

    The browser will resolve the protocol is HTTPS, the domain name is www.github.com, and the resource is /z

  3. The browser communicates with the ISP (Internet provider) and is resolved by DNS

    The DNS

    • Start by searching the browser’s own cache

    • Then search the hosts file and the operating system cache

    • The DNS server sends a request

      Firstly, the server is sent to the root server, which searches for the corresponding sub-server according to the domain name. After hierarchical recursive resolution, the final IP address may be obtained

    • Step up back to the browser

  4. The browser gets the IP address and replaces the original URL with https://192.168.12.1:443

    (Default HTTP port 80, default HTTPS port 443)

  5. The browser initiates a network request

    The network converts the application layer protocol layer (application layer, transport layer, network layer, data link layer, and no physical layer) into data signals at the physical layer

  6. The server receives the request from the browser and establishes a Tcp connection

  7. Access to the Nginx reverse proxy server, load balancing access to the Web server (Tomcat)

  8. Tomcat receives and processes the corresponding request

    • Access the data processing carried by the request to the corresponding controller
    • The controller handles the parameters to access the corresponding service
    • Service handles the corresponding business logic. When needed, call DAO to obtain persistent data of the database. A microservice project may make new RPC calls or Http calls to other services
    • The DAO layer accesses the database
    • The controller puts the returned results into the HTTP response
  9. The request then goes back to the browser with the response data layers

  10. The browser loads data or pages from the response, and a request ends the Tcp disconnect