lastSSEData returns the payload of the last "data: " line whose content is not "[DONE]".
(b []byte)
| 276 | |
| 277 | // lastSSEData returns the payload of the last "data: " line whose content is not "[DONE]". |
| 278 | func lastSSEData(b []byte) ([]byte, bool) { |
| 279 | prefix := []byte("data: ") |
| 280 | var last []byte |
| 281 | for _, line := range bytes.Split(b, []byte("\n")) { |
| 282 | line = bytes.TrimRight(line, "\r") |
| 283 | if bytes.HasPrefix(line, prefix) { |
| 284 | payload := line[len(prefix):] |
| 285 | if !bytes.Equal(payload, []byte("[DONE]")) { |
| 286 | last = payload |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | return last, last != nil |
| 291 | } |