Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private bool ProcessLine(out SseItem<T> sseItem)
return true;
}

_eventType = null;
_lineBuffer.Discard(advance);
sseItem = default;
return false;
Expand Down
19 changes: 19 additions & 0 deletions src/libraries/System.Net.ServerSentEvents/tests/SseParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@ await ReadAllEventsAsync(stream) :
AssertSseItemEqual(new SseItem<string>("This is the third message.", "message"), items[2]);
}

[Theory]
[MemberData(nameof(NewlineTrickleAsyncData))]
public async Task Parse_EventWithoutData_ResetsEventType(string newline, bool trickle, bool useAsync)
{
using Stream stream = GetStream(
$"event: stale{newline}id: 2{newline}retry: 300{newline}{newline}" +
$"data: first{newline}data: second{newline}{newline}" +
$"event: stale{newline}{newline}data: third{newline}{newline}", trickle);

List<SseItem<string>> items = useAsync ?
await ReadAllEventsAsync(stream) :
ReadAllEvents(stream);

Assert.Equal(2, items.Count);
AssertSseItemEqual(new SseItem<string>("first\nsecond", "message")
{ EventId = "2", ReconnectionInterval = TimeSpan.FromMilliseconds(300) }, items[0]);
AssertSseItemEqual(new SseItem<string>("third", "message"), items[1]);
}

[Theory]
[MemberData(nameof(NewlineTrickleAsyncData))]
public async Task Parse_HtmlSpec_Example2(string newline, bool trickle, bool useAsync)
Expand Down
Loading