-
-
Save serbrech/5281563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class EventStreamResponse : Response | |
{ | |
public EventStreamResponse(IResponseFormatter formatter, string id, dynamic body) | |
{ | |
var serializer = formatter.Serializers.FirstOrDefault(s => s.CanSerialize("application/json")); | |
ContentType = "text/event-stream"; | |
Contents = s => | |
{ | |
var idBytes = Encoding.UTF8.GetBytes(id + "\n"); | |
s.Write(idBytes, 0, idBytes.Length); | |
serializer.Serialize("application/json", body, s); | |
s.Flush(); | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment