Skip to content

Commit

Permalink
bug fix for null read
Browse files Browse the repository at this point in the history
  • Loading branch information
tillerstarredwards committed Feb 7, 2016
1 parent 65248aa commit ba4af5f
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions FireSharp/Response/EventStreamResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,27 @@ await Task.Factory.StartNew(async () =>
_cancel.Token.ThrowIfCancellationRequested();
var read = await sr.ReadLineAsync();
Debug.WriteLine(read);
if (read.StartsWith("event: "))
if (read != null)
{
eventName = read.Substring(7);
continue;
}

if (read.StartsWith("data: "))
{
if (eventName == "keep-alive")
if (read.StartsWith("event: "))
{
eventName = read.Substring(7);
continue;
}

if (string.IsNullOrEmpty(eventName))
if (read.StartsWith("data: "))
{
throw new InvalidOperationException("Payload data was received but an event did not preceed it.");
}
if (eventName == "keep-alive")
continue;

Update(eventName, read.Substring(6));
}
if (string.IsNullOrEmpty(eventName))
{
throw new InvalidOperationException("Payload data was received but an event did not preceed it.");
}

Update(eventName, read.Substring(6));
}
}
// start over
eventName = null;
}
Expand Down

0 comments on commit ba4af5f

Please sign in to comment.