4

Coming to HTTP conditional request, briefly, benefiting from the Etag and If-*, we can realize response cache(Etag+If-None-Match) and optimistic lock(Etag+If-Match).

As I see, it's convenient to perform the response cache using Spring which provides the specific filer ShallowEtagHeaderFilter to generate Etag value and check it against If-None-Match header. However, I cannot find corresponding components in Spring to do optimistic lock. Therefore, how can I implement that in Spring?

Sunny
  • 181
  • 1
  • 7

1 Answers1

0

I had the same issue. Didn't find any native way in Spring to check it. But you can always extract the headers and do manual comparisons. For example (in Kotlin):

@PutMapping
fun update(         
        @RequestHeader("If-Match") ifMatch: String?
) : ResponseEntity<Void>{

    if(ifMatch != null && ifMatch.trim() != computeETag()){
        return ResponseEntity.status(412).build()
    }
arcuri82
  • 885
  • 1
  • 8
  • 17