Class SseUtils
java.lang.Object
org.springframework.web.util.SseUtils
Utility methods for writing content as
Server-Sent Events,
shared by the Servlet and Reactive SSE support.
- Since:
- 7.0.9
- Author:
- Brian Clozel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendFieldValue(String field, String value, StringBuilder output) Appendvaluetooutput, replacing each line separator ("\n","\r", or"\r\n") it contains with a newfieldline (that is,"\n" + field + ":").static voidassertNoLineSeparator(String content) Assert that the given single-line SSE field value, such as anidoreventname, does not contain a line separator.
-
Constructor Details
-
SseUtils
public SseUtils()
-
-
Method Details
-
appendFieldValue
Appendvaluetooutput, replacing each line separator ("\n","\r", or"\r\n") it contains with a newfieldline (that is,"\n" + field + ":"). This keeps a multi-line field value from breaking out of the current SSE field when written on the wire.- Parameters:
field- the name of the SSE field thatvaluebelongs to (for example,"data"), or an empty string for a commentvalue- the field value to escape and appendoutput- theStringBuilderto append the escaped value to
-
assertNoLineSeparator
Assert that the given single-line SSE field value, such as anidoreventname, does not contain a line separator.- Parameters:
content- the field value to check- Throws:
IllegalArgumentException- ifcontentcontains"\n"or"\r"
-