Fix SSE data field to append instead of overwrite
Per the SSE specification, multiple data: lines within a single event should be concatenated with newline separators. Previously, each data: line overwrote the previous value.
This commit is contained in:
@@ -73,7 +73,12 @@ impl Decoder for ServerSentEventsCodec {
|
||||
self.next.event = Some(line);
|
||||
} else if line.starts_with(DATA) {
|
||||
line.drain(..DATA.len());
|
||||
self.next.data = Some(line)
|
||||
if let Some(ref mut existing) = self.next.data {
|
||||
existing.push('\n');
|
||||
existing.push_str(&line);
|
||||
} else {
|
||||
self.next.data = Some(line);
|
||||
}
|
||||
} else if line.starts_with(ID) {
|
||||
line.drain(..ID.len());
|
||||
self.next.id = Some(line);
|
||||
|
||||
Reference in New Issue
Block a user