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
-
So let’s start with the URL
-
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
-
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
-
-
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)
-
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
-
The server receives the request from the browser and establishes a Tcp connection
-
Access to the Nginx reverse proxy server, load balancing access to the Web server (Tomcat)
-
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
-
The request then goes back to the browser with the response data layers
-
The browser loads data or pages from the response, and a request ends the Tcp disconnect