Affects: 5.3.10.RELEASE and current main (30efa4d)


I'm making a SSE request to another server using WebClient w/ WebFlux, and the response from the WebClient always shows the results with leading whitespaces removed as well as trailing ones. I think it is due to ServerSentEventHttpMessageReader::buildEvent trimming every line:

data.append(line.substring(5).trim()).append('\n');

Is there any reason that leading whitespaces must be removed from the SSE response data? I wanted to use tabs at the start of each line to indent the text. I've tried other clients like curl but they show responses with the leading whitespaces preserved. Thanks in advance.

Comment From: poutsma

The spec says the following, under "If the line contains a U+003A COLON character (:)"

If value starts with a U+0020 SPACE character, remove it from value.

So it appears that using trim() is a bit too aggressive here, and should only remove the first space (if any); nothing more. I am working on a fix.

Comment From: poutsma

Related issue: https://github.com/spring-projects/spring-framework/issues/22043