Ignore HEAD requests in ShallowEtagHeaderFilter

Prior to this commit, the `ShallowEtagHeaderFilter` could participate in
the response and set its ETag/Content-Length headers, even for HEAD
requests. Since the response body is empty, the filter implementation
would set a `"Content-Length: 0"`.

The RFC states that responses to HEAD requests should exhibit identical
response headers to GET (with the possible exception of payload related
headers such as Content-Length.

With this commit, `ShallowEtagHeaderFilter` now ignores HEAD requests
since the proper values may be set already for payload related headers
by the handler. The filter has no way to generate a proper ETag value
nor calculate the content length without the actual body.

Issue: SPR-15261
This commit is contained in:
Brian Clozel
2017-02-20 11:58:22 +01:00
parent 598d9a4b05
commit b732251b09
2 changed files with 7 additions and 3 deletions

View File

@@ -46,6 +46,9 @@ public class ShallowEtagHeaderFilterTests {
assertTrue(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));
assertFalse(filter.isEligibleForEtag(request, response, 300, StreamUtils.emptyInput()));
request = new MockHttpServletRequest("HEAD", "/hotels");
assertFalse(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));
request = new MockHttpServletRequest("POST", "/hotels");
assertFalse(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));