Ensure StompEncoder never writes content-length twice

Issue: SPR-11984
This commit is contained in:
Rossen Stoyanchev
2014-07-11 10:09:48 -04:00
parent 85cdb9196e
commit b318880661
2 changed files with 16 additions and 1 deletions

View File

@@ -112,8 +112,12 @@ public final class StompEncoder {
for (Entry<String, List<String>> entry : nativeHeaders.entrySet()) {
byte[] key = encodeHeaderString(entry.getKey(), shouldEscape);
if (command.requiresContentLength() && "content-length".equals(entry.getKey())) {
continue;
}
List<String> values = entry.getValue();
if (StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
if (StompCommand.CONNECT.equals(command) &&
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
values = Arrays.asList(StompHeaderAccessor.getPasscode(headers));
}
for (String value : values) {

View File

@@ -290,6 +290,17 @@ public class StompCodecTests {
new Reactor11StompCodec().encoder().apply(frame).asString());
}
@Test
public void encodeFrameWithContentLengthPresent() {
StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND);
headers.setContentLength(12);
Message<byte[]> frame = MessageBuilder.createMessage("Message body".getBytes(), headers.getMessageHeaders());
assertEquals("SEND\ncontent-length:12\n\nMessage body\0",
new Reactor11StompCodec().encoder().apply(frame).asString());
}
private void assertIncompleteDecode(String partialFrame) {
Buffer buffer = Buffer.wrap(partialFrame);
assertNull(decode(buffer));