What happens when you type URL in your browser?

A lot, depends how deep down you want to go detailing it:


1. The line gets parsed and the protocol, server, port, query gets retrieved.
1.1. The mouse pointer is switched to hourglass.

2. Browser connects to server at the default/specified port.
2.1. If the server's name is in DNS cache then its ip address is retrieved.
2.2. The DNS server (already set up) is queried to resolve the IP address of www.google.com.

3. Browser sends a GET request followed a crlf sequence then by the headers all followed by respective crlf-s.
3.1 If this server has already cached cookies, the browser sends them as cookie headers.
3.2 If the browser supports compression it tells the server what compression is using (via headers) as well as what compression it could accept in return.
3.3 Sends a content-length header set to value "0".
3.4. Sends a header instructing the server how to denote the end of its transmission stream. Connection: Close would be the most common.
3.5 Sends a crlf sequence to mark the end of the headers (after eventual other headers are sent).

4. (Sends no message body)

5. Waits for the response which is composed by response code, status, crlf, headers all marked by separate crlf-s and the message body (same as during the send phase)
5.1. Parses the response code / status
5.2. If this response starts with 2 it caches cookies, decompresses (if header is mentioning compression) parses and displays the html content of message body (executing eventual scripts hooked to different DOM elements/events)
5.3 If the response code starts with 3 redirects t the server mentioned in the response (GOTO 1)
5.4 If the response code starts with 5 parses the response and displays it to the user

6. Mouse pointer is turned back from hourglass to normal

Comments