SPR-5825 - ShallowEtagHeaderFilter doesn't work: response body is empty
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright ${YEAR} the original author or authors.
|
||||
* Copyright 2002-2009 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.
|
||||
@@ -90,4 +90,30 @@ public class ShallowEtagHeaderFilterTest {
|
||||
assertArrayEquals("Invalid content", new byte[0], response.getContentAsByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterWriter() throws Exception {
|
||||
final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
|
||||
String etag = "\"0b10a8db164e0754105b7a99be72e3fe5\"";
|
||||
request.addHeader("If-None-Match", etag);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
FilterChain filterChain = new FilterChain() {
|
||||
|
||||
public void doFilter(ServletRequest filterRequest, ServletResponse filterResponse)
|
||||
throws IOException, ServletException {
|
||||
assertEquals("Invalid request passed", request, filterRequest);
|
||||
((HttpServletResponse) filterResponse).setStatus(HttpServletResponse.SC_OK);
|
||||
String responseBody = "Hello World";
|
||||
FileCopyUtils.copy(responseBody, filterResponse.getWriter());
|
||||
}
|
||||
};
|
||||
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
assertEquals("Invalid status", 304, response.getStatus());
|
||||
assertEquals("Invalid ETag header", "\"0b10a8db164e0754105b7a99be72e3fe5\"", response.getHeader("ETag"));
|
||||
assertEquals("Invalid Content-Length header", 0, response.getContentLength());
|
||||
assertArrayEquals("Invalid content", new byte[0], response.getContentAsByteArray());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user