Restrict ETag generation in ShallowEtagHeaderFilter

Prior to this commit, all 2xx HTTP responses were eligible for ETag
generation in ShallowEtagHeaderFilter. In some cases, this would use
CPU resources for no reason since HTTP clients would not use ETags.

This commit is an optimization and restricts ETags generation in cases
where (all conditions must be met):
- response has a 2xx status
- request is a GET
- response does not contain "no-store" in its "Cache-Control" header

Issue: SPR-11110
This commit is contained in:
Brian Clozel
2014-02-13 22:08:44 +01:00
parent d550ffb37f
commit 6fba8292f5
2 changed files with 24 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +48,13 @@ public class ShallowEtagHeaderFilterTests {
assertTrue(filter.isEligibleForEtag(request, response, 200, new byte[0]));
assertFalse(filter.isEligibleForEtag(request, response, 300, new byte[0]));
request = new MockHttpServletRequest("POST", "/hotels");
assertFalse(filter.isEligibleForEtag(request, response, 200, new byte[0]));
request = new MockHttpServletRequest("POST", "/hotels");
request.addHeader("Cache-Control","must-revalidate, no-store");
assertFalse(filter.isEligibleForEtag(request, response, 200, new byte[0]));
}
@Test