Charu Garg
Charu Garg

Reputation: 1

How to add support for Shallow ETag in ResponseEntity Spring Java

I understand that we can create the filter for Shallow E tag in spring. However, i am looking if there is an easier way to do it. I am using HttpEntity in my code for getting the response. The code looks like this

return ResponseEntity.ok()
                    .eTag(getETag(preloadMap))
                    .body(preloadMap);

However, I am looking forward to options of changing this etag to Shallow etag in a simpler way.

Upvotes: 0

Views: 938

Answers (1)

Daniel Domingueti
Daniel Domingueti

Reputation: 99

I think using spring filter is the easiest way to implement shallow etag. Within three lines it's done.

@Configuration
public MyConfigClass () {
    @Bean
    public Filter shallowEtagHeaderFilter() {
        return new ShallowEtagHeaderFilter();
    }
}

This filter is in charge of generating a hash response and adding it up to the etag header.

It also verifies if the created hash matches with the existing etag from "if-none-match". If both are equal it returns 304 Not modified. Otherwise it just returns 200 OK.

Upvotes: 0

Related Questions