Get content as String for ContentCachingRequestWrapper
This commits adds a getContentAsString method to ContentCachingRequestWrapper that uses the configured charset without copying the underlying byte array. See gh-30709
This commit is contained in:
parent
d529eee889
commit
d9b8826142
|
@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
@ -196,6 +197,14 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper {
|
||||||
return this.cachedContent.toByteArray();
|
return this.cachedContent.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the cached request content as a String. The Charset used to decode
|
||||||
|
* the cached content is the same as returned by getCharacterEncoding.
|
||||||
|
*/
|
||||||
|
public String getContentAsString() {
|
||||||
|
return this.cachedContent.toString(Charset.forName(getCharacterEncoding()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template method for handling a content overflow: specifically, a request
|
* Template method for handling a content overflow: specifically, a request
|
||||||
* body being read that exceeds the specified content cache limit.
|
* body being read that exceeds the specified content cache limit.
|
||||||
|
|
Loading…
Reference in New Issue