StreamUtils.emptyInput() for consistent empty InputStream exposure
Issue: SPR-13563
This commit is contained in:
@@ -39,7 +39,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import javax.servlet.AsyncContext;
|
||||
import javax.servlet.DispatcherType;
|
||||
import javax.servlet.RequestDispatcher;
|
||||
@@ -59,6 +58,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -122,7 +122,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
|
||||
private static final String CHARSET_PREFIX = "charset=";
|
||||
|
||||
private static final ServletInputStream EMPTY_SERVLET_INPUT_STREAM =
|
||||
new DelegatingServletInputStream(new ByteArrayInputStream(new byte[0]));
|
||||
new DelegatingServletInputStream(StreamUtils.emptyInput());
|
||||
|
||||
/**
|
||||
* Date formats as specified in the HTTP RFC
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package org.springframework.web.filter;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.test.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.test.MockHttpServletResponse;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@@ -36,27 +35,23 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class ShallowEtagHeaderFilterTests {
|
||||
|
||||
private ShallowEtagHeaderFilter filter;
|
||||
private final ShallowEtagHeaderFilter filter = new ShallowEtagHeaderFilter();
|
||||
|
||||
@Before
|
||||
public void createFilter() throws Exception {
|
||||
filter = new ShallowEtagHeaderFilter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEligibleForEtag() {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
assertTrue(filter.isEligibleForEtag(request, response, 200, new ByteArrayInputStream(new byte[0])));
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 300, new ByteArrayInputStream(new byte[0])));
|
||||
assertTrue(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 300, StreamUtils.emptyInput()));
|
||||
|
||||
request = new MockHttpServletRequest("POST", "/hotels");
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 200, new ByteArrayInputStream(new byte[0])));
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));
|
||||
|
||||
request = new MockHttpServletRequest("POST", "/hotels");
|
||||
request.addHeader("Cache-Control","must-revalidate, no-store");
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 200, new ByteArrayInputStream(new byte[0])));
|
||||
assertFalse(filter.isEligibleForEtag(request, response, 200, StreamUtils.emptyInput()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,9 +115,7 @@ public class ShallowEtagHeaderFilterTests {
|
||||
assertArrayEquals("Invalid content", new byte[0], response.getContentAsByteArray());
|
||||
}
|
||||
|
||||
// SPR-12960
|
||||
|
||||
@Test
|
||||
@Test // SPR-12960
|
||||
public void filterWriterWithDisabledCaching() throws Exception {
|
||||
final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels");
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
Reference in New Issue
Block a user