Skip to content

Commit c654495

Browse files
committed
fix(response-handling): handle empty SSE lines and "ping" events #97
Previously, the response body callback would crash when encountering an empty line followed by a non-null SSE instance, or when receiving a "ping" event. This commit adds a check to handle both scenarios gracefully by ignoring the "ping" events and resetting the SSE instance when an empty line is received. This ensures the stability and reliability of the response handling logic.
1 parent 8c68a29 commit c654495

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/kotlin/cc/unitmesh/devti/llms/azure/ResponseBodyCallback.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ class ResponseBodyCallback(private val emitter: FlowableEmitter<SSE>, private va
6464
sse = when {
6565
line!!.startsWith("data:") -> {
6666
val data = line!!.substring(5).trim { it <= ' ' }
67-
SSE(data)
67+
// data: ping - 2024-03-05 02:07:20.310586
68+
if (data.startsWith("ping") || data.startsWith(" ping")) {
69+
null
70+
} else {
71+
SSE(data)
72+
}
6873
}
6974

7075
line == "" && sse != null -> {

0 commit comments

Comments
 (0)