@@ -167,10 +167,10 @@ fn parse_sse_events(body: &str) -> Vec<SseEvent> {
167167 let mut current_data = Vec :: < String > :: new ( ) ;
168168
169169 for line in body. lines ( ) {
170- if line. starts_with ( "event: " ) {
171- current_event = line [ "event: " . len ( ) .. ] . to_string ( ) ;
172- } else if line. starts_with ( "data: " ) {
173- current_data. push ( line [ "data: " . len ( ) .. ] . to_string ( ) ) ;
170+ if let Some ( stripped ) = line. strip_prefix ( "event: " ) {
171+ current_event = stripped . to_string ( ) ;
172+ } else if let Some ( stripped ) = line. strip_prefix ( "data: " ) {
173+ current_data. push ( stripped . to_string ( ) ) ;
174174 } else if line. is_empty ( ) && !current_event. is_empty ( ) {
175175 events. push ( SseEvent {
176176 event : std:: mem:: take ( & mut current_event) ,
@@ -562,10 +562,10 @@ fn streaming_eval_post(
562562 Ok ( l) => l,
563563 Err ( _) => break ,
564564 } ;
565- if line. starts_with ( "event: " ) {
566- current_event = line [ "event: " . len ( ) .. ] . to_string ( ) ;
567- } else if line. starts_with ( "data: " ) {
568- current_data. push ( line [ "data: " . len ( ) .. ] . to_string ( ) ) ;
565+ if let Some ( stripped ) = line. strip_prefix ( "event: " ) {
566+ current_event = stripped . to_string ( ) ;
567+ } else if let Some ( stripped ) = line. strip_prefix ( "data: " ) {
568+ current_data. push ( stripped . to_string ( ) ) ;
569569 } else if line. is_empty ( ) && !current_event. is_empty ( ) {
570570 let event = SseEvent {
571571 event : std:: mem:: take ( & mut current_event) ,
0 commit comments