From f9167c3df59edbca2f8a99541750d87957d34a49 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Fri, 9 Jul 2021 20:34:22 +0100 Subject: [PATCH] Improve Javadoc of ContentCachingRequestWrapper Closes gh-27068 --- .../web/util/ContentCachingRequestWrapper.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java b/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java index 0158ed87b97..faa0ccbf643 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,9 +40,15 @@ import org.springframework.lang.Nullable; * the {@linkplain #getInputStream() input stream} and {@linkplain #getReader() reader}, * and allows this content to be retrieved via a {@link #getContentAsByteArray() byte array}. * + *

This class acts as an interceptor that only caches content as it is being + * read but otherwise does not cause content to be read. That means if the request + * content is not consumed, then the content is not cached, and cannot be + * retrieved via {@link #getContentAsByteArray()}. + * *

Used e.g. by {@link org.springframework.web.filter.AbstractRequestLoggingFilter}. * Note: As of Spring Framework 5.0, this wrapper is built on the Servlet 3.1 API. * + * * @author Juergen Hoeller * @author Brian Clozel * @since 4.1.3 @@ -184,6 +190,10 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper { /** * Return the cached request content as a byte array. *

The returned array will never be larger than the content cache limit. + *

Note: The byte array returned from this method + * reflects the amount of content that has has been read at the time when it + * is called. If the application does not read the content, this method + * returns an empty array. * @see #ContentCachingRequestWrapper(HttpServletRequest, int) */ public byte[] getContentAsByteArray() {