@Test public void verifyBrokenUpCRLF() throws Exception { ServerEventDecoder serverEventDecoder = new ServerEventDecoder(sseCallback); serverEventDecoder.onReceivedContentPart(buffer("event: ClientCommand\r\ndata: test1\r\n\n")); serverEventDecoder.onReceivedContentPart(buffer("event: ClientCommand\r")); serverEventDecoder.onReceivedContentPart(buffer("\ndata: test2\r\n\n")); assertEquals(2, sseCallback.count); Event event1 = sseCallback.poll(); Event event2 = sseCallback.poll(); assertEquals("ClientCommand", event1.event); assertEquals("ClientCommand", event2.event); }
public void onReceivedContentPart(ByteBuf content) throws KingHttpException { String contentString = content.toString(StandardCharsets.UTF_8); try { char[] chars = contentString.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (chars[i] == '\r') { continue; } if (isNewLine(c)) { String line = buffer.toString(); buffer.setLength(0); parseLine(line); } else { buffer.append(c); } } } catch (Exception e) { throw new KingHttpException("Failed to parse incoming content in SSE stream", e); } }
ServerEventDecoder { public void onReceivedContentPart(ByteBuf content) throws KingHttpException { String contentString = content.toString(StandardCharsets.UTF_8); try { char[] chars = contentString.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (chars[i] == '\r') { continue; } if (isNewLine(c)) { String line = buffer.toString(); buffer.setLength(0); parseLine(line); } else { buffer.append(c); } } } catch (Exception e) { throw new KingHttpException("Failed to parse incoming content in SSE stream", e); } } }
ServerEventDecoder { public void onReceivedContentPart(ByteBuf content) throws KingHttpException { String contentString = content.toString(StandardCharsets.UTF_8); try { char[] chars = contentString.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (chars[i] == '\r') { continue; } if (isNewLine(c)) { String line = buffer.toString(); buffer.setLength(0); parseLine(line); } else { buffer.append(c); } } } catch (Exception e) { throw new KingHttpException("Failed to parse incoming content in SSE stream", e); } } ServerEventDecoder(SseClientCallback sseClientCallback); }
ServerEventDecoder { public void onReceivedContentPart(ByteBuf content) throws KingHttpException { String contentString = content.toString(StandardCharsets.UTF_8); try { char[] chars = contentString.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (chars[i] == '\r') { continue; } if (isNewLine(c)) { String line = buffer.toString(); buffer.setLength(0); parseLine(line); } else { buffer.append(c); } } } catch (Exception e) { throw new KingHttpException("Failed to parse incoming content in SSE stream", e); } } ServerEventDecoder(SseClientCallback sseClientCallback); void reset(); void onReceivedContentPart(ByteBuf content); }
ServerEventDecoder { public void onReceivedContentPart(ByteBuf content) throws KingHttpException { String contentString = content.toString(StandardCharsets.UTF_8); try { char[] chars = contentString.toCharArray(); for (int i = 0; i < chars.length; i++) { char c = chars[i]; if (chars[i] == '\r') { continue; } if (isNewLine(c)) { String line = buffer.toString(); buffer.setLength(0); parseLine(line); } else { buffer.append(c); } } } catch (Exception e) { throw new KingHttpException("Failed to parse incoming content in SSE stream", e); } } ServerEventDecoder(SseClientCallback sseClientCallback); void reset(); void onReceivedContentPart(ByteBuf content);  }