Skip to content

Commit ac1a14e

Browse files
committed
[v8.2.0] Lib.AspNetCore.ServerSentEvents
1 parent 09f6db0 commit ac1a14e

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Lib.AspNetCore.ServerSentEvents 8.2.0
2+
### Additions and Changes
3+
- Added options for controlling the format of [keepalives](https://tpeczek.github.io/Lib.AspNetCore.ServerSentEvents/articles/getting-started.html#keepalives).
4+
- Added options for controlling the [`Accept` request header validation](https://tpeczek.github.io/Lib.AspNetCore.ServerSentEvents/articles/getting-started.html#accept-request-header-validation).
5+
16
## Lib.AspNetCore.ServerSentEvents 8.1.0
27
### Additions and Changes
38
- Removed upper bounds on some of the .NET Framework dependencies versions

DocFx.AspNetCore.ServerSentEvents/articles/getting-started.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ The interval after which client attempts to reconnect can be controlled by the a
104104

105105
## Keepalives
106106

107-
Keepalives are supported in three [modes](../api/Lib.AspNetCore.ServerSentEvents.ServerSentEventsKeepaliveMode.html). By default the will be automatically send if ANCM is detected, but both the mode and interval can be changed per `ServerSentEventsService` type.
107+
Keepalives are supported in three [modes](../api/Lib.AspNetCore.ServerSentEvents.ServerSentEventsKeepaliveMode.html). By default they will be automatically send if ANCM is detected, but both the mode and interval can be changed per `ServerSentEventsService` type.
108108

109109
```cs
110110
public class Startup
@@ -124,4 +124,50 @@ public class Startup
124124

125125
...
126126
}
127+
```
128+
129+
In addition, the format of keepalives can also be configured. The options include choosing the [kind](../api/Lib.AspNetCore.ServerSentEvents.ServerSentEventsKeepaliveKind.html) of the content to send (comment or event) as well as setting the content itself.
130+
131+
```cs
132+
public class Startup
133+
{
134+
public void ConfigureServices(IServiceCollection services)
135+
{
136+
...
137+
138+
services.AddServerSentEvents<INotificationsServerSentEventsService, NotificationsServerSentEventsService>(options =>
139+
{
140+
...
141+
options.KeepaliveKind = ServerSentEventsKeepaliveKind.Event;
142+
options.KeepaliveContent = "PING";
143+
});
144+
145+
...
146+
}
147+
148+
...
149+
}
150+
```
151+
152+
## Accept Request Header Validation
153+
154+
The part of HTML Standard specifications which covers Server-Sent Events doesn't force user agents to set `Accept: text/event-stream`, it's optional. Because of that, by default, this library will accepts request with `Accept` header which value includes `text/event-stream` or request without `Accept` header. Sometimes this may not be desired behavior, so there is an option which allows for introducing string requirement for request to contain `Accept` header including `text/event-stream` value.
155+
156+
```cs
157+
public class Startup
158+
{
159+
...
160+
161+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
162+
{
163+
...
164+
165+
app.MapServerSentEvents("/default-sse-endpoint", new ServerSentEventsOptions
166+
{
167+
RequireAcceptHeader = true
168+
});
169+
170+
...
171+
}
172+
}
127173
```

Lib.AspNetCore.ServerSentEvents/Lib.AspNetCore.ServerSentEvents.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<Description>Lib.AspNetCore.ServerSentEvents is a library which provides Server-Sent Events (SSE) support for ASP.NET Core</Description>
44
<Copyright>Copyright © 2017 - 2022 Tomasz Pęczek</Copyright>
5-
<VersionPrefix>8.1.0</VersionPrefix>
5+
<VersionPrefix>8.2.0</VersionPrefix>
66
<VersionSuffix></VersionSuffix>
77
<Authors>Tomasz Pęczek</Authors>
88
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net461</TargetFrameworks>

0 commit comments

Comments
 (0)