-
Bug
-
Resolution: Unresolved
-
Neutral
-
None
-
5.6
-
None
CacheResponseWrapper#getBufferedContent tries to cast a generic OutputStream into a ByteArrayOutputStream in order to extract already written content. Otherwise it simply returns an empty array (instead of already buffered content).
This is particularly relevant for cases where response content exceeds the given size threshold. The output buffer gets replaced by a different one (see CacheResponseWrapper.ThresholdingCacheOutputStream#thresholdReached).
Test code to reproduce
final byte[] payload = "Foo bar baz".getBytes(); final HttpServletResponse originalResponse = mock(HttpServletResponse.class); when(originalResponse.getOutputStream()).thenReturn(new SimpleServletOutputStream(new ByteArrayOutputStream())); final HttpServletResponse target = mock(HttpServletResponse.class); final ByteArrayOutputStream targetStream = new ByteArrayOutputStream(); when(target.getOutputStream()).thenReturn(new SimpleServletOutputStream(targetStream)); final CacheResponseWrapper serveWrapper = new CacheResponseWrapper(originalResponse, payload.length - 1, true); serveWrapper.getOutputStream().write(payload); serveWrapper.replayContent(target, true); assertThat(targetStream.toByteArray(), is(payload)); // fails
Acceptance criteria