Skip to content

Commit

Permalink
[v8.3.0] Lib.AspNetCore.ServerSentEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
tpeczek committed Sep 25, 2023
1 parent f8037eb commit c23ffa7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Lib.AspNetCore.ServerSentEvents 8.3.0
### Additions and Changes
- Added support for scenario when multiple types are provided as `Accept` header value (thanks to @krebil)
- Added support for wildcard (`*/*` and `text/*`) mime types (thanks to @krebil)

## Lib.AspNetCore.ServerSentEvents 8.2.0
### Additions and Changes
- Added options for controlling the format of [keepalives](https://tpeczek.github.io/Lib.AspNetCore.ServerSentEvents/articles/getting-started.html#keepalives).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>Lib.AspNetCore.ServerSentEvents is a library which provides Server-Sent Events (SSE) support for ASP.NET Core</Description>
<Copyright>Copyright © 2017 - 2023 Tomasz Pęczek</Copyright>
<VersionPrefix>8.2.0</VersionPrefix>
<VersionPrefix>8.3.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<Authors>Tomasz Pęczek</Authors>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net461</TargetFrameworks>
Expand Down
10 changes: 4 additions & 6 deletions Lib.AspNetCore.ServerSentEvents/ServerSentEventsMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ServerSentEventsMiddleware<TServerSentEventsService> where TServerS
private readonly ServerSentEventsOptions _serverSentEventsOptions;
private readonly ILogger<ServerSentEventsMiddleware<TServerSentEventsService>> _logger;
private readonly bool _clientDisconnectServicesAvailable = false;
private readonly HashSet<string> AcceptedHeaders = new() { "*/*", "text/*", Constants.SSE_CONTENT_TYPE };
private readonly HashSet<string> _acceptableContentTypes = new() { "*/*", "text/*", Constants.SSE_CONTENT_TYPE };

private AuthorizationPolicy _authorizationPolicy;
#endregion
Expand Down Expand Up @@ -116,8 +116,6 @@ public async Task Invoke(HttpContext context, IPolicyEvaluator policyEvaluator)
}
}



private bool CheckAcceptHeader(IHeaderDictionary requestHeaders)
{
if (!requestHeaders.ContainsKey(Constants.ACCEPT_HTTP_HEADER))
Expand All @@ -130,7 +128,7 @@ private bool CheckAcceptHeader(IHeaderDictionary requestHeaders)
return !_serverSentEventsOptions.RequireAcceptHeader;
}

if (requestHeaders.GetCommaSeparatedValues(Constants.ACCEPT_HTTP_HEADER).Any(acceptHeaderValue => AcceptedHeaders.Contains(acceptHeaderValue)))
if (requestHeaders.GetCommaSeparatedValues(Constants.ACCEPT_HTTP_HEADER).Any(_acceptableContentTypes.Contains))
{
return true;
}
Expand Down Expand Up @@ -219,7 +217,7 @@ private async Task ForbidAsync(HttpContext context)
}
}

private void DisableResponseBuffering(HttpContext context)
private static void DisableResponseBuffering(HttpContext context)
{
#if !NET461
IHttpResponseBodyFeature responseBodyFeature = context.Features.Get<IHttpResponseBodyFeature>();
Expand All @@ -236,7 +234,7 @@ private void DisableResponseBuffering(HttpContext context)
#endif
}

private void HandleContentEncoding(HttpContext context)
private static void HandleContentEncoding(HttpContext context)
{
context.Response.OnStarting(ResponseOnStartingCallback, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public async Task Invoke_SseRequestWithoutAcceptHeaderAndAcceptHeaderRequired_Do
[InlineData("*/*")]
[InlineData("text/*")]
[InlineData(SSE_CONTENT_TYPE)]
public async Task Invoke_SseRequestWithAcceptedHeader_Accepts(string header)
public async Task Invoke_SseRequestWithAcceptedHeader_Accepts(string contentType)
{
ServerSentEventsMiddleware<ServerSentEventsService> serverSentEventsMiddleware = SubjectUnderTestHelper.PrepareServerSentEventsMiddleware();
HttpContext context = SubjectUnderTestHelper.PrepareHttpContext(acceptHeaderValue: header);
HttpContext context = SubjectUnderTestHelper.PrepareHttpContext(acceptHeaderValue: contentType);

await serverSentEventsMiddleware.Invoke(context, null);

Expand Down

0 comments on commit c23ffa7

Please sign in to comment.