Common sense: What happens after you enter a URL (common sense, but who can explain white?) )

Source: Internet
Author: User
Tags send cookies domain name server browser cache domain server

1. First, enter the URL

Taking www.facebook.com as an example

  2. Browser lookup domain name corresponding IP

  2.1 DNS Lookup process:

Browser Cache--the browser logs DNS for a period of time (2-30 minutes, depending on the browser)

System Cache-The browser does not find the DNS cache, this thing browser make a system call (window is gethostbyname). If a match is found, it is used. (This corresponds to a host malicious hijacking change attack)

Router Cache--the router also has a DNS cache (caches the websites you've been on, so sometimes the routers need DNS refresh)

ISP DNS Caching--Next is the lookup on the cache of the DNS servers of the ISP (Internet service provider).

Recursive lookup--dns in the cache, the ISP DNS server obtains the IP from the root name server (root), the. com top-level domain server, and the Facebook domain name server, which is usually available in the cache, so this step will not happen.

  2.2 Multi-IP domain DNS query solution

Loop dns--A single domain name, multiple IP lists to cycle through DNS queries

Load Balancer-A Load Balancer server for a specific IP (for example, a reverse proxy server) is responsible for listening for requests and forwarding to one of the following multiple server clusters for multiple server load Balancing

Geo-dns--returns different IPs depending on the location of the user (application: CDN)

anycast--A routing technique that maps multiple physical hosts with an IP address

  3. Sending the request

Once the IP of the domain name is obtained, the HTTP (S) request is started.

Detailed Request Header:

GET http://facebook.com/HTTP/1.1

Accept:application/x-ms-application, Image/jpeg, Application/xaml+xml, [...]

user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; [...]

Accept-encoding:gzip, deflate

Connection:keep-alive

Host:facebook.com

Cookie:datr=1265876274-[...]; Locale=en_us; Lsd=ww[...]; C_user=2101[...]

The request tells the server:

1. I want to get (get) http://facebook.com/(get URL) this page

2. Accept: I can accept these types of files

3. What type of browser do I use on which operating system?

4. Acknowledge the manner in which compressed files are accepted

5. Connection type: Short connection? Long connection?

6. Host Domain name

7. Send cookies stored on this computer to the server

In addition to sending a GET request, you can also send a submit response request (e.g., search to be sent to the server for processing (add a specific user parameter after the request URL) to obtain a specific content)

Note: The difference between the slash and no slash after the URL (the difference between a folder and a single file)

Http://www.facebook.com

http://www.facebook.com/

When we enter http://www.facebook.com, the browser will automatically add a slash to ensure that the URL is rigorous.

When we enter: Http://www.facebook.com/folderOrFile, because the browser is not clear whether Folderorfile is a folder or a file, so you cannot automatically add a slash. At this point, the browser does not have a slash directly access to the address, the server responds to a redirect, resulting in an unnecessary handshake.

  4. Redirection

When we enter an incomplete URL http://www.facebook.com, or if the site migration does redirect settings, the server makes a redirect response.

The following is the response header returned after redirection:

http/1.1 301 Moved Permanently

Cache-control:private, No-store, No-cache, Must-revalidate, post-check=0,pre-check=0

Expires:sat, 00:00:00 GMT

location:http://www.facebook.com/

p3p:cp= "DSP Law"

Pragma:no-cache

set-cookie:made_write_conn=deleted; Expires=thu, 12-feb-2009 05:09:50 GMT;

path=/; domain=.facebook.com; HttpOnly

content-type:text/html; Charset=utf-8

X-cnection:close

Date:fri, 05:09:51 GMT

content-length:0

1.301 Permanent redirect

2. New Location: ...

Why redirect instead of directly returning what the user wants to see? (Since the server has been redirected to know what the user needs)

Answer: One of the reasons: related to search engine rankings. You see, if a page has two addresses, like http://www.igoro.com/and http://igoro.com/, the search engine will think of them as two sites, resulting in fewer search links and less rankings. and search engine know 301 permanent redirect is what meaning, so will visit with www and without WWW address to the same site ranking.

  5. New Requests

A new fetch request is posted after the redirect

  6. Server processing Requests

  6.1 Web Server Software

Type of server operating system: Linux (typically manufacturer based on open source customization), Windows Server family (Microsoft)

Major Server Software: IIS, Apache, Tomcat, JBOSS, Nginx, LIGHTTPD, Tetty

The role of server Software: receiving, processing, and responding to requests (understanding the role of CGI)

  6.2 Process Flow:

Web server software (such as IIS or Apache) receives an HTTP request

Determine the execution of the request handler (a program that can read the request and generate HTML to respond) (for example: Asp.net,php,ruby ... ) to handle it

Request processor read request header parameters and cookie information

Update information on the server: for example, update database information, service-side cookies

Generates HTML, compresses (gzip or other), responds to requests sent to the user

  7. The server sends back an HTML response

Responses include response Headers (response parameters and information), response packages (principal files)

The response packet is compressed in a specific way, the entire response is transmitted as a BLOB type, and the response header indicates how the response packet is compressed

This response header is not the same as the redirected response header, which also contains caching options, cookies settings and privacy information, etc.

  8. The browser starts to display HTML

The browser has already started displaying the page without fully receiving all the HTML files.

  9. The browser gets other files

When the browser parses the HTML and encounters a file that needs to be downloaded, it sends a request to the server (CDN) to get the file again.

Attention:

1. Dynamic pages cannot be cached, and static files allow the browser to cache.

2. Static files are locally cached when read directly from local

3. The request response header contains the duration of the static file save, and the browser knows how long the static file is to be kept silent.

4. The response header will also have the etag of the static file (equivalent to the version number), and when the browser discovers that the requested static file's response header's ETag does not match the existing cache file, it will again get the static file to the server.

  10. The browser sends an asynchronous (AJAX) request

A major feature of Web 2.0 is that the client remains in contact with the server after the page is fully displayed (keep-alive)

The browser executes the specific JS code to send an asynchronous request to the server, to get the latest dynamic message, so that the page can maintain a relatively new state.

HTTP is a request-response protocol that only the server can respond to when the client sends the request, and cannot proactively send the message or document to the customer. So, to keep the page up to date, you need to poll periodically (send AJAX requests periodically to update page content)

The AJAX request is very easy to change, and the user is very easy to make and send Ajax requests, so there is no verification code without the IP restrictions of voting is a small game (refer to Studio two times brush ticket: Their own definition of IP, their own timing to send AJAX requests, and then the ticket on the rushing).

Optimization scenario: If the server is polled without new messages, it will ignore the client. In the case where the request has not timed out, if a new message is received from the client, the server finds the outstanding request and sends the new message to the client as a response (so that it does not have to respond frequently to the request)

From: www.jianshu.com

[Turn] common sense: What happens after you enter a URL (common sense, but who can explain the white?) )

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.