From the input URL to the page display in front of the user, what happened?

Source: Internet
Author: User
Tags domain name server

The whole is divided into the following processes:

    • DNS resolution
    • TCP connections
    • Send HTTP request
    • The server processes and returns an HTTP message
    • Browser parsing Render page
    • End of connection

Specific process
1. DNS resolution
The process of DNS resolution is to find out which machine has the process you need resources. When the input www.baidu.com, in fact, to find the corresponding IP address, DNS as the role of translation, the implementation of the URL to the IP address conversion. Because the unique identity of each computer on the Internet is its IP address.

Parsing process:

DNS parsing is the process of a recursive query.

First, the local domain name server to query the IP address, if not found, the local name server will send a request to the root name server, if the root name server also does not exist the domain name, the local domain name will send a request to the COM top-level domain name server, and so on. Until the last local domain name server to get Baidu's IP address and cache it locally for the next query to use. From the above process, it can be seen that the resolution of the URL is a right-to-left process: com, baidu.com, www.baidu.com. But have you found something missing, the root name server parsing process? In fact The real URL is www.baidu.com. It's not that I hit one more. This is the root name server, which is the last of all URLs by default., since it is by default, in order to facilitate the user, usually omitted, the browser in the request of DNS will be automatically added, all URLs the real parsing process is : . . com, baidu.com. -Www.baidu.com.

2. TCP connection
3. HTTP request
In fact, this part can also be referred to as the front-end engineer in the eyes of HTTP, it mainly occurs in the client. The process of sending an HTTP request is to build an HTTP request message and send it to the server specified port (HTTP protocol 80/8080, HTTPS protocol 443) via the TCP protocol. The HTTP request message consists of three parts: the request line, the request header, and the request body.
Request Line

The format is as follows:

Method Request-URL HTTP-Version CRLF

Eg:get index.html http/1.1
Common methods are: GET, POST, PUT, DELETE, OPTIONS, HEAD.

Todo:

What is the difference between get and post?
Request Header

The request header allows the client to pass the requested additional information to the server and the client's own information.
PS: The client does not necessarily refer specifically to the browser, sometimes using the Curl command under Linux and the HTTP Client Test tool.
Common request headers are: Accept, Accept-charset, accept-encoding, Accept-language, Content-type, Authorization, cookies, user-agent, etc.

Request Body

When using methods such as post, put, and so on, the client is typically required to pass data to the server. The data is stored in the request body. There are some information related to the request body in the request header, for example: Today's web apps typically use a rest schema, and the requested data format is generally JSON. Then you need to set Content-type:application/json.

4. The server processes and returns HTTP messages
Naturally this part corresponds to the HTTP in the back-end engineer's eyes. The backend begins with receiving a TCP message on a fixed port, which corresponds to the socket in the programming language. The TCP connection is processed, the HTTP protocol is parsed, and the HTTP request object is further encapsulated in the message format for use by the upper layer. This part of the work is usually done by the Web server, the Web server I used has tomcat, jetty and Netty, and so on.

The HTTP response message is also composed of three parts: A status code, a response header, and a response message.

Status code

The status code is made up of 3 digits, the first number defines the category of the response, and there are five possible values:

1XX: Indicates information – indicates that the request has been received and continues processing.
2XX: Success – Indicates that the request has been successfully received, understood, accepted.
3XX: Redirect – A further step must be made to complete the request.
4XX: Client Error – The request has a syntax error or the request cannot be implemented.
5XX: Server-side Error – The server failed to implement a legitimate request. Usually encountered more common status codes are: 200, 204, 301, 302, 304, 400, 401, 403, 404, 422, 500 (respectively, please find out what to do).
Todo:

What's the difference between 301 and 302?
HTTP caching
Response header

The common response header fields are: Server, Connection ....

Response message

The server returns the text information to the browser, usually HTML, CSS, JS, pictures and other files in this section.

5. Browser parsing Render page

Reference: Http://blog.csdn.net/aishangy ...

From the input URL to the page display in front of the user, what happened?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.