Polish ContentCachingResponseWrapper[Tests]
This commit is contained in:
@@ -38,7 +38,7 @@ import org.springframework.util.FastByteArrayOutputStream;
|
||||
/**
|
||||
* {@link jakarta.servlet.http.HttpServletResponse} wrapper that caches all content written to
|
||||
* the {@linkplain #getOutputStream() output stream} and {@linkplain #getWriter() writer},
|
||||
* and allows this content to be retrieved via a {@link #getContentAsByteArray() byte array}.
|
||||
* and allows this content to be retrieved via a {@linkplain #getContentAsByteArray() byte array}.
|
||||
*
|
||||
* <p>Used e.g. by {@link org.springframework.web.filter.ShallowEtagHeaderFilter}.
|
||||
*
|
||||
@@ -120,9 +120,16 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
|
||||
return this.writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method neither flushes content to the client nor commits the underlying
|
||||
* response, since the content has not yet been copied to the response.
|
||||
* <p>Invoke {@link #copyBodyToResponse()} to copy the cached body content to
|
||||
* the wrapped response object and flush its buffer.
|
||||
* @see jakarta.servlet.ServletResponseWrapper#flushBuffer()
|
||||
*/
|
||||
@Override
|
||||
public void flushBuffer() throws IOException {
|
||||
// do not flush the underlying response as the content has not been copied to it yet
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,15 +146,11 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper {
|
||||
throw new IllegalArgumentException("Content-Length exceeds ContentCachingResponseWrapper's maximum (" +
|
||||
Integer.MAX_VALUE + "): " + len);
|
||||
}
|
||||
int lenInt = (int) len;
|
||||
if (lenInt > this.content.size()) {
|
||||
this.content.resize(lenInt);
|
||||
}
|
||||
this.contentLength = lenInt;
|
||||
setContentLength((int) len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentType(String type) {
|
||||
public void setContentType(@Nullable String type) {
|
||||
this.contentType = type;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user