diff options
Diffstat (limited to 'src/cow_sse.erl')
-rw-r--r-- | src/cow_sse.erl | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/cow_sse.erl b/src/cow_sse.erl index 710e9b3..201989f 100644 --- a/src/cow_sse.erl +++ b/src/cow_sse.erl @@ -64,14 +64,14 @@ parse(Data0, State=#state{state_name=bom, buffer=Buffer}) -> parse(<<>>, State=#state{buffer=Buffer}) -> parse_event(Buffer, State#state{buffer= <<>>}); %% Otherwise process the input data as-is. -parse(Data, State) -> - parse_event(Data, State). - -parse_event(Data0, State0=#state{buffer=Buffer}) -> +parse(Data0, State=#state{buffer=Buffer}) -> Data = case Buffer of <<>> -> Data0; _ -> << Buffer/binary, Data0/binary >> end, + parse_event(Data, State). + +parse_event(Data, State0) -> case binary:split(Data, [<<"\r\n">>, <<"\r">>, <<"\n">>]) of [Line, Rest] -> case parse_line(Line, State0) of @@ -211,4 +211,12 @@ parse_example4_test() -> {more, _} = parse(<<>>, State), ok. +parse_split_event_test() -> + {more, State} = parse(<< + "data: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA">>, init()), + {event, _, _} = parse(<<"==\n\n">>, State), + ok. + -endif. |