Header values are optional in Stomp 1.1 and 1.2

This commit is contained in:
Josh King
2015-06-09 14:06:46 -07:00
committed by Rossen Stoyanchev
parent c41779f895
commit 11824893a9
2 changed files with 20 additions and 3 deletions

View File

@@ -215,10 +215,10 @@ public class StompDecoder {
if (headerStream.size() > 0) {
String header = new String(headerStream.toByteArray(), UTF8_CHARSET);
int colonIndex = header.indexOf(':');
if (colonIndex <= 0 || colonIndex == header.length() - 1) {
if (buffer.remaining() > 0) {
if (colonIndex <= 0) {
if(buffer.remaining() > 0) {
throw new StompConversionException("Illegal header: '" + header +
"'. A header must be of the form <name>:<value>.");
"'. A header must be of the form <name>:[<value>].");
}
}
else {

View File

@@ -188,6 +188,23 @@ public class StompCodecTests {
assertEquals(StompCommand.DISCONNECT, StompHeaderAccessor.wrap(messages.get(1)).getCommand());
}
@Test
public void decodeFrameWithHeaderWithEmptyValue() {
String accept = "accept-version:1.1\n";
String valuelessKey = "key:\n";
Message<byte[]> frame = decode("CONNECT\n" + accept + valuelessKey + "\n\0");
StompHeaderAccessor headers = StompHeaderAccessor.wrap(frame);
assertEquals(StompCommand.CONNECT, headers.getCommand());
assertEquals(2, headers.toNativeHeaderMap().size());
assertEquals("1.1", headers.getFirstNativeHeader("accept-version"));
assertEquals("", headers.getFirstNativeHeader("key"));
assertEquals(0, frame.getPayload().length);
}
@Test
public void decodeFrameWithIncompleteCommand() {
assertIncompleteDecode("MESSAG");