HTTP Request Header label If-Modified_Since

Source: Internet
Author: User
Tags fiddler2

Address: http://www.bianceng.cn/webkf/aspx/201108/28533_2.htm

 

I have never noticed the IMS (if-modified-since) label of the HTTP request header.

Recently, an error occurred while analyzing the access. Log File of squid.

That is, even if an HTTP request is made to the same file, the network traffic data generated for the first and second times is inconsistent.

During the investigation, we gradually learned the role of the HTTP if-modified-Since Header label.

We all know that the client browser has a cache, which stores some web files that have been accessed before.

For example, ie will save the cached file to "C: \ Documents ents and Settings \ zh2000g \ Local Settings \ Temporary Internet Files"

In such a directory.

In fact, the cache stores not only webpage files, but also the last modification time of the file sent by the server.

If-modified-since is a standard HTTP Request Header label. When sending an HTTP request, it sends the last modification of the browser cache page to the server, the server compares the time with the last modification time of the actual file on the server.

If the time is the same, the HTTP status code 304 (no file content is returned) is returned. After the client receives the request, the local cached file is directly displayed in the browser.

If the time is inconsistent, the HTTP Status Code 200 and the new file content are returned. After receiving the request, the client discards the old file, caches the new file, and displays it in the browser.

The following is a simple example.

Because the HTTP request and response information need to be intercepted in the demo, the tool I use here is Fiddler.

If you are interested, go to [http://www.fiddler2.com/fiddler2/version.asp;to download the file.

1. Create a simple HTML file on the server and access it in a browser. The HTML page is displayed successfully. Fiddler generates the following capture information.

Note that

(1) because this is the first time you access this page, when the client sends a request, the request header does not contain the IF-modified-since tag.

(2) The HTTP status code returned by the server is 200 and all the content on the page is sent.

(3) The HTTP header label returned by the server contains last-modified, indicating the last modification time of the client page.

2. Refresh the page in the browser, and fiddler will generate the following capture information.

Note that:

(1) When the client sends an HTTP request, it uses the IF-modified-since label to return the last modification time of the file that the last server told it to the server.

(2) because the file has not been changed, the HTTP status code returned by the server is 304, and no page content is sent.

3. Use a text editor to slightly change the page file and save it. Access it with a browser, and fiddler will generate the following captured information.

Note that

(1) When the client sends an HTTP request, it uses the IF-modified-since label to return the last modification time of the file that the last server told it to the server.

(2) because the file has been changed and the time on both sides is inconsistent, the HTTP status code returned by the server is 200 and the full content of the new page is sent.

(3) The HTTP header label returned by the server contains last-modified, indicating the last modification time of the client page.

The HTTP if-modified-Since Header label works with the client cache, greatly Saving network traffic.

 

 

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.