Skip to content

Commit 17055a3

Browse files
paulhdkczechboy0
andauthored
EventStreams: check for terminating byte sequence after removing trailing \n
Co-authored-by: Honza Dvorsky <honza@apple.com>
1 parent 91c7815 commit 17055a3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Sources/OpenAPIRuntime/EventStreams/ServerSentEventsDecoding.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ extension ServerSentEventsDeserializationSequence.Iterator {
199199
buffer.removeFirst()
200200
if line.isEmpty {
201201
// Dispatch the accumulated event.
202-
state = .accumulatingEvent(.init(), buffer: buffer)
203202
// If the last character of data is a newline, strip it.
204203
if event.data?.hasSuffix("\n") ?? false { event.data?.removeLast() }
205-
206-
if let data = event.data {
207-
if !predicate(ArraySlice(Data(data.utf8))) {
208-
return .returnNil
209-
}
204+
205+
state = .accumulatingEvent(.init(), buffer: buffer)
206+
207+
if let data = event.data, !predicate(ArraySlice(data.utf8)) {
208+
state = .finished
209+
return .returnNil
210210
}
211211
return .emitEvent(event)
212212
}

0 commit comments

Comments
 (0)