当前位置:网站首页>Common interview questions: Browser input domain name and open the completed process

Common interview questions: Browser input domain name and open the completed process

2022-06-09 07:18:00 Ah, SEI

Interview answer :

1. Enter the domain name in the browser address bar

2.DNS analysis IP

3. Sending http Before request , to DNS Domain name resolution , Get access to IP Address

4. Browser sends... To server tcp Connect , Build with browser tcp Three handshakes

5. After a successful handshake , Browser to server http request

6. Server receives request , Process and return the response

7. The browser received the server HTTP Response content

8. Browser rendering , analysis HTML Generate DOM Trees , analysis CSS Generate rule tree ,js Engine parsing js

9. Rendering complete , Four waves , close tcp Connect

Detailed instructions :

One 、DNS Domain name resolution IP Address

        1. First look in the browser cache IP, Because browsers cache DNS Record a period of time

        2. If not found , And then find the operating system

        3. If not found , Then search from the router cache

        4. If not , Again from ISP DNS Cache lookup

        5. If we don't find any , Browser domain name server to the root domain >COM Top-level domain > The secondary domain

Two 、TCP Three handshakes ,( according to ip establish TCP Connect )

         The first handshake : The client sends a... To the server SYN message , And indicate the initialization serial number of the client ISN. At this time, the client is in SYN_Send state .

         The second handshake : The server received... From the client SYN After the message , Will take their own SYN Message as reply , And it also specifies its own initialization sequence number ISN(s), At the same time, the client will ISN + 1 As ACK Value , Indicates that you have received the SYN, The server is in SYN_REVD The state of

         The third handshake : Client received SYN After the message , Will send a ACK message , Of course , It's the same with the server ISN + 1 As ACK Value , Indicates that the server has received SYN message , At this time, the client is in establised state

         Server received ACK After the message , Also in establised state , here , Both sides have established a link to

3、 ... and 、HTTP Request sent to server

         The request line includes : Request method ,URL, Protocol version ; for example :GET + Space + /xxxxx/login.html + Space + HTTP/1.1

Request header field :

        Cookie: The client can bring data to the server through this header , This is one of the most important request headers .

        User-Agent:User-Agent The content of the header field contains the requested user information .

        Accept: Browser acceptable MIME type .

        Accept-Charset: Browser acceptable character set .

        Accept-Encoding: The data encoding method that the browser can decode

        Accept-Language: The kind of language the browser wants

        Authorization: Authorization information , It usually appears in... Sent to the server WWW-Authenticate In the head's reply .

        Content-Length: Indicates the length of the request message body .

        Host: The client tells the server through this header , Host name you want to access .Host The header field specifies the Intenet Host and port number , A request must be made url Location of the original server or gateway .HTTP/1.1 The request must contain the host header domain , Otherwise, the system will use 400 Status code returns .

Four 、 Server processing request , Browser accepts HTTP Respond to

The response line is defined by the protocol version 、 The state code and its description are composed of ; Such as :HTTP/1.1 200 OK

The protocol version HTTP/1.1 perhaps HTTP/1.0,200 It's the status code ,OK Is its description .

Common status codes are as follows :

        1xx: Indicates that the server has received a client request , The client can continue to send requests ;

        2xx: Indicates that the server has successfully received the request and processed ;

        3xx: Indicates that the server requires client redirection ;

        4xx: Indicates that the client's request has illegal content ;

        5xx: Indicates that the server failed to properly process the client's request with an unexpected error , Server error ;

The status code description text has the following values :

        200 OK: Indicates that the client request is successful ;

        400 Bad Request: Indicates that the client request has a syntax error , Not understood by the server ;

        401 Unauthonzed: Indicates that the request is not authorized , The status code must be associated with WWW-Authenticate Header fields are used together ;

        403 Forbidden: Indicates that the server received a request , But refused to provide service , The reason why the service is not provided is usually given in the response body ;

        404 Not Found: Requested resource does not exist , for example , I typed the wrong one URL;

        500 Internal Server Error: Indicates that an unexpected error occurred on the server , The client's request could not be completed ;

        503 Service Unavailable: Indicates that the server is currently unable to process the client's request , After a period of time , The server may return to normal ;

5、 ... and 、 Page rendering , structure DOM Trees

        1、 The server processes through the background language program , Find the data and return it to the browser

        2、HTML The string is read and parsed sentence by sentence after being accepted by the browser , Resolved to link Tag and resend the request to get css

        3、 Resolved to sript After the tag, send a request to get js, And execute the code , The browser will render

        4、 Browser according to HTML and CSS Calculate the rendering tree , Draw on the screen ,js Will be performed  

        5、 After parsing DOM Trees and CSS The rule tree is associated to build the rendering tree , Calculate layout , Draw page

6、 ... and 、TCP Four waves ( disconnect )

         First wave : The client sends one FIN message , A serial number... Will be specified in the message . At this time, the client is in FIN_WAIT1 state .

         Second wave : Server received FIN after , Will send ACK message , And the client's serial number value + 1 As ACK The value of the message's serial number , Indicates that a message has been received from the client , At this time, the server is in CLOSE_WAIT state .

         Third wave : If the server wants to disconnect too , Same as the first wave of the client , issue FIN message , And specify a serial number . At this time, the server is in LAST_ACK The state of .

         Fourth wave : Client received FIN after , Send a ACK Message as reply , And the server serial number value + 1 As myself ACK The value of the message's serial number , At this time, the client is in TIME_WAIT state . It will take a while to ensure that the server receives its own ACK The message will enter after CLOSED state .
         Server received ACK After the message , It's closing the connection , be in CLOSED state

原网站

版权声明
本文为[Ah, SEI]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021422529503.html