What is HTTP ETag? - GeeksforGeeks

29 Jun, 2020
An entity tag (ETag) is an HTTP header used for Web cache validation and conditional request from browsers to resources. The value of an ETag is an identifier that represents a specific version of the resource. Additionally, ETags help prevents simultaneous updates of a resource from overwriting each other. Example of ETag header is
ETag: "version1"
Note :The value of the ETag header must be in double-quotes.
The server receives an HTTP request for a particular resource.
The server generates a response and attached an ETag header. For Eg: ETag: “response_version1”.
The server sends the response with the above header with the status code 200. Then the application represents the resource and at the same time caches the resource copy along with header information.
Later the same application makes another request for the same resource with following conditional request header: If-None-Match: “response_version1”
On receiving the request for the resource along with the ‘If-None-Match’ header, the server-side logic compare the current value of the ETag identifier on the server-side and the one which is received in the request header.
If the request’s If-None-Match is the same as the currently generated value of ETag on the server, then status code 304 (Not Modified) with the empty body is sent back and the application uses the cached copy of the resource.
If the request’s If-None-Match value doesn’t match the currently generated/assigned value of ETag (say “response_version2”) for the same resource then the server sends back the new content in the body along with status code 200. The ‘ETag’ header with the new value is also included in the response. The application uses the new resource and updates its cache with the new data.
That’s entirely up to the application to generate it as it wants. It can be created and updated manually or can be auto-generated. Common methods of its auto-generation include using a hash of the resource’s content or just a hash of the last modification timestamp. The generated hash should be collision-free.
It is just comparison of two values. It is divided into 2 parts
Strong ValidationWeak Validation
Strong Validation
Weak Validation
1.Strong Validation:
The different resource representations are byte-for-byte identical. This is the default validation of ETag and no special directive is used for it.
2.Weak Validation:
The two resource representations are semantically equivalent. For e.g. the current date displayed on the page might not be important for updating the entire resource for it.
References:
https://en.wikipedia.org/wiki/HTTP_ETaghttps://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
https://en.wikipedia.org/wiki/HTTP_ETag
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
jyash97
Advanced Computer Subject
Computer Subject
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
ML | Linear Regression
Copying Files to and from Docker Containers
Decision Tree
System Design Tutorial
Python | Decision tree implementation
SDE SHEET - A Complete Guide for SDE Preparation
Introduction to Algorithms
Software Engineering | Coupling and Cohesion
Software Engineering | Prototyping Model
Difference between NP hard and NP complete problem