Trim decoded SSE data

Fixes #22043
This commit is contained in:
Rossen Stoyanchev 2019-01-18 18:13:58 -05:00
parent ef72ef54fa
commit 5dcde9e7d7
1 changed files with 6 additions and 6 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -119,21 +119,21 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader<Objec
for (String line : lines) { for (String line : lines) {
if (line.startsWith("data:")) { if (line.startsWith("data:")) {
data = (data != null ? data : new StringBuilder()); data = (data != null ? data : new StringBuilder());
data.append(line.substring(5)).append("\n"); data.append(line.substring(5).trim()).append("\n");
} }
if (shouldWrap) { if (shouldWrap) {
if (line.startsWith("id:")) { if (line.startsWith("id:")) {
sseBuilder.id(line.substring(3)); sseBuilder.id(line.substring(3).trim());
} }
else if (line.startsWith("event:")) { else if (line.startsWith("event:")) {
sseBuilder.event(line.substring(6)); sseBuilder.event(line.substring(6).trim());
} }
else if (line.startsWith("retry:")) { 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(":")) { else if (line.startsWith(":")) {
comment = (comment != null ? comment : new StringBuilder()); comment = (comment != null ? comment : new StringBuilder());
comment.append(line.substring(1)).append("\n"); comment.append(line.substring(1).trim()).append("\n");
} }
} }
} }