diff options
author | Loïc Hoguin <[email protected]> | 2017-06-16 16:13:19 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2017-06-16 16:13:19 +0200 |
commit | 21bb4295eb380fd38123a1983559fe6c7d59fa27 (patch) | |
tree | ac48829e39dd575b86fb8d2b226382d182f5266e | |
parent | a636afd8ccb8258fbf24f7ae1d44d174b66cc95b (diff) | |
download | cowlib-21bb4295eb380fd38123a1983559fe6c7d59fa27.tar.gz cowlib-21bb4295eb380fd38123a1983559fe6c7d59fa27.tar.bz2 cowlib-21bb4295eb380fd38123a1983559fe6c7d59fa27.zip |
Fix parsing of event spanning multiple parse calls
-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. |