Efficient STOMP content-length header check
Issue: SPR-14747
(cherry picked from commit a6b0b6e)
This commit is contained in:
@@ -102,7 +102,7 @@ public class BufferingStompDecoder {
|
|||||||
this.chunks.add(newBuffer);
|
this.chunks.add(newBuffer);
|
||||||
checkBufferLimits();
|
checkBufferLimits();
|
||||||
|
|
||||||
if (getExpectedContentLength() != null && getBufferSize() < this.expectedContentLength) {
|
if (this.expectedContentLength != null && getBufferSize() < this.expectedContentLength) {
|
||||||
return Collections.<Message<byte[]>>emptyList();
|
return Collections.<Message<byte[]>>emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,12 +139,12 @@ public class BufferingStompDecoder {
|
|||||||
if (this.expectedContentLength != null) {
|
if (this.expectedContentLength != null) {
|
||||||
if (this.expectedContentLength > this.bufferSizeLimit) {
|
if (this.expectedContentLength > this.bufferSizeLimit) {
|
||||||
throw new StompConversionException(
|
throw new StompConversionException(
|
||||||
"'content-length' header value " + this.expectedContentLength +
|
"STOMP 'content-length' header value " + this.expectedContentLength +
|
||||||
" exceeds configured message buffer size limit " + this.bufferSizeLimit);
|
" exceeds configured buffer size limit " + this.bufferSizeLimit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getBufferSize() > this.bufferSizeLimit) {
|
if (getBufferSize() > this.bufferSizeLimit) {
|
||||||
throw new StompConversionException("The configured stomp frame buffer size limit of " +
|
throw new StompConversionException("The configured STOMP buffer size limit of " +
|
||||||
this.bufferSizeLimit + " bytes has been exceeded");
|
this.bufferSizeLimit + " bytes has been exceeded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,21 +29,21 @@ import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
|||||||
import org.springframework.messaging.simp.SimpMessageType;
|
import org.springframework.messaging.simp.SimpMessageType;
|
||||||
import org.springframework.messaging.support.MessageHeaderAccessor;
|
import org.springframework.messaging.support.MessageHeaderAccessor;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.util.MimeType;
|
import org.springframework.util.MimeType;
|
||||||
import org.springframework.util.MimeTypeUtils;
|
import org.springframework.util.MimeTypeUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@code MessageHeaderAccessor} to use when creating a {@code Message} from a
|
* A {@code MessageHeaderAccessor} to use when creating a {@code Message} from
|
||||||
* decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame.
|
* a decoded STOMP frame, or when encoding a {@code Message} to a STOMP frame.
|
||||||
*
|
*
|
||||||
* <p>When created from STOMP frame content, the actual STOMP headers are stored
|
* <p>When created from STOMP frame content, the actual STOMP headers are
|
||||||
* in the native header sub-map managed by the parent class
|
* stored in the native header sub-map managed by the parent class
|
||||||
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor}
|
* {@link org.springframework.messaging.support.NativeMessageHeaderAccessor}
|
||||||
* while the parent class
|
* while the parent class {@link SimpMessageHeaderAccessor} manages common
|
||||||
* {@link org.springframework.messaging.simp.SimpMessageHeaderAccessor} manages
|
* processing headers some of which are based on STOMP headers
|
||||||
* common processing headers some of which are based on STOMP headers (e.g.
|
* (e.g. destination, content-type, etc).
|
||||||
* destination, content-type, etc).
|
|
||||||
*
|
*
|
||||||
* <p>An instance of this class can also be created by wrapping an existing
|
* <p>An instance of this class can also be created by wrapping an existing
|
||||||
* {@code Message}. That message may have been created with the more generic
|
* {@code Message}. That message may have been created with the more generic
|
||||||
@@ -502,12 +502,8 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Integer getContentLength(Map<String, List<String>> nativeHeaders) {
|
public static Integer getContentLength(Map<String, List<String>> nativeHeaders) {
|
||||||
if (nativeHeaders.containsKey(STOMP_CONTENT_LENGTH_HEADER)) {
|
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER);
|
||||||
List<String> values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER);
|
return (!CollectionUtils.isEmpty(values) ? Integer.valueOf(values.get(0)) : null);
|
||||||
String value = (values != null ? values.get(0) : null);
|
|
||||||
return Integer.valueOf(value);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user