提交 774e4c3d 编写于 作者: C Christoph Dreis

Improve performance of StompEncoder

Fixes SPR-14747
上级 099350a2
......@@ -81,7 +81,10 @@ public final class StompEncoder {
}
else {
StompCommand command = StompHeaderAccessor.getCommand(headers);
Assert.notNull(command, "Missing STOMP command: " + headers);
if (command == null) {
throw new IllegalStateException("Missing STOMP command: " + headers);
}
output.write(command.toString().getBytes(StandardCharsets.UTF_8));
output.write(LF);
writeHeaders(command, headers, payload, output);
......@@ -115,22 +118,25 @@ public final class StompEncoder {
boolean shouldEscape = (command != StompCommand.CONNECT && command != StompCommand.CONNECTED);
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 (StompCommand.CONNECT.equals(command) &&
StompHeaderAccessor.STOMP_PASSCODE_HEADER.equals(entry.getKey())) {
values = Arrays.asList(StompHeaderAccessor.getPasscode(headers));
}
byte[] encodedKey = encodeHeaderString(entry.getKey(), shouldEscape);
for (String value : values) {
output.write(key);
output.write(encodedKey);
output.write(COLON);
output.write(encodeHeaderString(value, shouldEscape));
output.write(LF);
}
}
if (command.requiresContentLength()) {
int contentLength = payload.length;
output.write("content-length:".getBytes(StandardCharsets.UTF_8));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册