Class SseUtils

java.lang.Object
org.springframework.web.util.SseUtils

public abstract class SseUtils extends Object
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 Details

    • SseUtils

      public SseUtils()
  • Method Details

    • appendFieldValue

      public static void appendFieldValue(String field, String value, StringBuilder output)
      Append value to output, replacing each line separator ("\n", "\r", or "\r\n") it contains with a new field line (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 that value belongs to (for example, "data"), or an empty string for a comment
      value - the field value to escape and append
      output - the StringBuilder to append the escaped value to
    • assertNoLineSeparator

      public static void assertNoLineSeparator(String content)
      Assert that the given single-line SSE field value, such as an id or event name, does not contain a line separator.
      Parameters:
      content - the field value to check
      Throws:
      IllegalArgumentException - if content contains "\n" or "\r"