File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed
Lib.AspNetCore.ServerSentEvents Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ public class ServerSentEventsMiddleware
1414 #region Fields
1515 private readonly RequestDelegate _next ;
1616 private readonly ServerSentEventsService _serverSentEventsService ;
17+
18+ private static readonly Task _completedTask = Task . FromResult < object > ( null ) ;
1719 #endregion
1820
1921 #region Constructor
@@ -41,7 +43,7 @@ public async Task Invoke(HttpContext context)
4143 {
4244 DisableResponseBuffering ( context ) ;
4345
44- context . Response . Headers . Append ( Constants . CONTENT_ENCODING_HEADER , Constants . IDENTITY_CONTENT_ENCODING ) ;
46+ HandleContentEncoding ( context ) ;
4547
4648 await context . Response . AcceptSse ( ) ;
4749
@@ -78,6 +80,19 @@ private void DisableResponseBuffering(HttpContext context)
7880 bufferingFeature . DisableResponseBuffering ( ) ;
7981 }
8082 }
83+
84+ private void HandleContentEncoding ( HttpContext context )
85+ {
86+ context . Response . OnStarting ( ( ) =>
87+ {
88+ if ( ! context . Response . Headers . ContainsKey ( Constants . CONTENT_ENCODING_HEADER ) )
89+ {
90+ context . Response . Headers . Append ( Constants . CONTENT_ENCODING_HEADER , Constants . IDENTITY_CONTENT_ENCODING ) ;
91+ }
92+
93+ return _completedTask ;
94+ } ) ;
95+ }
8196 #endregion
8297 }
8398}
You can’t perform that action at this time.
0 commit comments