What happens when you type google.com in your browser and press Enter
Have you ever wondered what happens when you type an URL and press enter? This blog post will explain what is going on under the hood as clearly as possible.
1) Find the IP of google.com (URL) through DNS:
What is DNS?
Wikipedia definition:
The Domain Name System is the hierarchical and decentralized naming system used to identify computers reachable through the Internet or other Internet Protocol networks.
In other words, ?DNS is a list of URLs, and their IP addresses, it matches URLs with IPs. Without the correct IP, the browser can not access the webserver and get us the webpage.
To understand it clearly, think of DNS as a Google Maps It routes you to your destination. Your device already knows the address of the DNS server. When you type the URL in a browser for the first time, it sends a request to the DNS server, which response back with the IP address of the webserver hosting. However, if you had visited that URL before, that value is usually kept in the browser's cache so it doesn’t have to do this lookup every time.
2) The browser initiates a TCP connection with the server :
Now that the browser has the correct IP, it can establish a connection with the IP server to get the data. Internet protocols are used by browsers to create such connections. Various internet protocols may be utilized, however, TCP is the most often used protocol for many sorts of HTTP requests.
A TCP connection must be established between your computer (client) and the server to transport data packets. This connection is made using a procedure known as the TCP/IP three-way handshake. To establish a connection, the client and server exchange SYN (synchronize) and ACK (acknowledge) messages in three steps.
1. The client sends an SYN packet to the server through the internet, inquiring whether it is accepting new connections.
2 . When the server has open ports that can accept and initiate new connections, it’ll respond with an ACKnowledgment of the SYN packet
3. The client will receive the SYN/ACK packet from the server and will acknowledge it by sending an ACK packet.
And finally, the TCP connection has been made.!
3) HTTP request to the webserver.
Once the TCP connection is established, it is time to transfer the data expected. This is done through a GET/POST request.
Below there is an example of a get HTTP request:
?This request will also contain additional information such as browser identification (User-Agent?header), types of requests that it will accept, and connection headers asking it to keep the TCP connection alive for additional requests. It will also pass information taken from cookies that the browser has already stored.
领英推荐
The infrastructure would look like this:
The components/agents of this infrastructure are:
4) The server takes the request and sends back a response.
The server has a web server that accepts the browser's request and forwards it to a request handler to read and create a response. A request handler is a software that examines the request, its headers, and cookies to determine what is being requested. Then it will give back together with a response in a certain format like for example JSON.
5) The server sends an HTTP response.
The server response includes the requested web page as well as the status code, compression type, any cookies to set, and privacy information, among other info.
Above there is an example of an HTTP server response, as you can see in the first line, there is a number that indicates the status code of the response. It gives you valuable information about whether the request succeeded or not.
These are the possible status codes:
● 1xx indicates an informational message only
● 2xx indicates the success of some kind
● 3xx redirects the client to another URL
● 4xx indicates an error on the client’s part
● 5xx indicates an error on the server’s part
6) Finally, the browser displays the content requested
The HTML material is displayed in stages by the browser. It will first render the bare-bones HTML skeleton. Then it will examine the HTML tags and send GET requests for other web page elements. The browser caches these static files so that it does not have to retrieve them again the next time you visit the page. Finally, google.com will show in your browser and you will be available to interact with the website.
And that's it! Hope it was interesting. Feel free to like, comment, or share this article if it was useful.