ContentCachingRequestWrapper requires cacheLimit

Closes gh-33914
This commit is contained in:
rstoyanchev
2024-11-25 15:56:25 +00:00
parent b027cf110d
commit 1164ac3079
2 changed files with 49 additions and 52 deletions

View File

@@ -71,31 +71,34 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
/**
* Create a new ContentCachingRequestWrapper for the given servlet request.
* @param request the original servlet request
* @param cacheLimit the maximum number of bytes to cache per request;
* no limit is set if the value is 0 or less. It is recommended to set a
* concrete limit in order to avoid using too much memory.
* @since 4.3.6
* @see #handleContentOverflow(int)
*/
public ContentCachingRequestWrapper(HttpServletRequest request) {
public ContentCachingRequestWrapper(HttpServletRequest request, int cacheLimit) {
super(request);
int contentLength = request.getContentLength();
this.cachedContent = (contentLength > 0) ? new FastByteArrayOutputStream(contentLength) : new FastByteArrayOutputStream();
this.contentCacheLimit = null;
this.cachedContent = (contentLength > 0 ?
new FastByteArrayOutputStream((cacheLimit > 0 ? Math.min(contentLength, cacheLimit) : contentLength)) :
new FastByteArrayOutputStream());
this.contentCacheLimit = (cacheLimit > 0 ? cacheLimit : null);
}
/**
* Create a new ContentCachingRequestWrapper for the given servlet request.
* @param request the original servlet request
* @param contentCacheLimit the maximum number of bytes to cache per request
* @since 4.3.6
* @see #handleContentOverflow(int)
* @deprecated in favor of {@link #ContentCachingRequestWrapper(HttpServletRequest, int)}
* in order to explicitly choose the cache limit
*/
public ContentCachingRequestWrapper(HttpServletRequest request, int contentCacheLimit) {
@Deprecated(since = "6.2.1", forRemoval = true)
public ContentCachingRequestWrapper(HttpServletRequest request) {
super(request);
int contentLength = request.getContentLength();
if (contentLength > 0) {
this.cachedContent = new FastByteArrayOutputStream(Math.min(contentLength, contentCacheLimit));
}
else {
this.cachedContent = new FastByteArrayOutputStream();
}
this.contentCacheLimit = contentCacheLimit;
this.cachedContent = (contentLength > 0 ?
new FastByteArrayOutputStream(contentLength) : new FastByteArrayOutputStream());
this.contentCacheLimit = null;
}