Browse Source

Trim decoded SSE data

Fixes #22043
pull/22392/head
Rossen Stoyanchev 7 years ago
parent
commit
5dcde9e7d7
  1. 12
      spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java

12
spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@ -119,21 +119,21 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec @@ -119,21 +119,21 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
for (String line : lines) {
if (line.startsWith("data:")) {
data = (data != null ? data : new StringBuilder());
data.append(line.substring(5)).append("\n");
data.append(line.substring(5).trim()).append("\n");
}
if (shouldWrap) {
if (line.startsWith("id:")) {
sseBuilder.id(line.substring(3));
sseBuilder.id(line.substring(3).trim());
}
else if (line.startsWith("event:")) {
sseBuilder.event(line.substring(6));
sseBuilder.event(line.substring(6).trim());
}
else if (line.startsWith("retry:")) {
sseBuilder.retry(Duration.ofMillis(Long.valueOf(line.substring(6))));
sseBuilder.retry(Duration.ofMillis(Long.valueOf(line.substring(6).trim())));
}
else if (line.startsWith(":")) {
comment = (comment != null ? comment : new StringBuilder());
comment.append(line.substring(1)).append("\n");
comment.append(line.substring(1).trim()).append("\n");
}
}
}

Loading…
Cancel
Save