diff --git a/Program.cs b/Program.cs index c3559e3..7994973 100644 --- a/Program.cs +++ b/Program.cs @@ -20,8 +20,8 @@ namespace youtube_downloader public class SSE { public static SSE ServerSentEventItem = new SSE(); - List Streams = new List(); - public void RegisterStreamWriter(StreamWriter rp) + List Streams = new List(); + public void RegisterStreamWriter(HttpListenerResponse rp) { Streams.Add(rp); } @@ -40,11 +40,9 @@ namespace youtube_downloader { try { - if(items.BaseStream != null) - { - items.Write(raw_data); - items.Write("\n\n"); - } + var bytes = Encoding.UTF8.GetBytes(raw_data + "\n\n"); + await items.OutputStream.WriteAsync(bytes, 0, bytes.Length); + await items.OutputStream.FlushAsync(); } catch (Exception ex) { @@ -309,8 +307,10 @@ namespace youtube_downloader { rp.AddHeader("Cache-Control", "no-cache"); rp.ContentType = "text/event-stream"; - StreamWriter w = new StreamWriter(rp.OutputStream, rp.ContentEncoding); - SSE.ServerSentEventItem.RegisterStreamWriter(w); + rp.WithCode(); + rp.ContentEncoding = Encoding.UTF8; + + SSE.ServerSentEventItem.RegisterResponse(rp); diff --git a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache index 01a8130..abef78d 100644 Binary files a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache and b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache differ