I'm new to spring boot. I want to generate ETAG whenever perform a POST from my controller class.
Below is the configuration class created:
@Configuration
public class WebConfiguration {
@Bean
public Filter shallowEtagHeaderFilter() {
return new ShallowEtagHeaderFilter();
}
}
My main class is annotated with @EnableAutoConfiguration
.
As per my understanding, the response object that I receive from POST should provide me the ETAG header.
Please can anyone provide a spring boot sample to generate ETag during my POST/GET?PUT call.
Generating ETag ValueIt 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.
An ETag (entity tag) is an HTTP response header returned by an HTTP/1.1 compliant web server used to determine change in content at a given URL. It can be considered to be the more sophisticated successor to the Last-Modified header.
Step by step: we first create and retrieve a Resource – and store the ETag value for further use. then we update the same Resource. send a new GET request, this time with the “If-None-Match” header specifying the ETag that we previously stored.
The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource. It lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content was not changed.
The ShallowEtagHeaderFilter
you are using will only generate an ETag in response to a GET
request.
When you perform a GET
on the resource you just created/updated, the ETag header will be present.
It is also worth nothing that if you are making use of the Spring Repository REST exporter (i.e. Spring Data Rest), then it has ETag support built in. All that is required is for your entity classes to have a Long
or Timestamp
field annotated with @javax.persistence.Version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With