The ETag field of the HTTP protocol

Source: Internet
Author: User

http://www.cnblogs.com/hust-ghtao/: Hua ke xiao Tao:

The previous time to participate in a company's interview, asked me etag field, when said is not very clear, found some information, collation for this article.

simple ETag is similar to the fingerprint of a resource entity, and they can be quickly compared to determine whether the two versions of the resource are the same . The ETag comparison is only meaningful for the same URL-the ETag values of resources on different URLs may or may not be the same, and they cannot be inferred from the comparison of their etag.

The header field ETag can tell the client entity identity. It is a way to uniquely identify a resource as a string. The server assigns a corresponding ETag value for each resource, and the ETag value needs to be updated when the resource is updated. Common methods for generating an etag include using the anti-collision hash function on the resource content, using the hash of the recently modified timestamp, or even just a version number.

In a typical usage, when a URL is requested, the Web server returns the resource and its corresponding ETag value, which is placed in the "ETag" field of http:

   1:"686897696a7c876b7e"

The client can then decide whether to cache the resource and its etag. Later, if the client wants to request the same URL again, it will send a request containing the saved ETag and the "If-none-match" field.

   1:"686897696a7c876b7e"

After a client request, the server may compare the etag of the client and the ETag of the current version of the resource. If the ETag value matches, which means that the resource has not changed, the server sends back a very short response that contains the HTTP "304 unmodified" state. The 304 status tells the client that its cached version is up-to-date and should use it.

However, if the value of the ETag does not match, which means that the resource is likely to change, then a complete response is returned, including the contents of the resource, as if the etag was not being used. In this case, the client can replace the previous cached version with the newly returned resource and the new ETag.

The ETag field of the HTTP protocol

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.