Skip to content

Commit 7c3a072

Browse files
API docs for WebSockets (#26470)
1 parent e2b1b20 commit 7c3a072

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

src/Middleware/WebSockets/src/ExtendedWebSocketAcceptContext.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@
66

77
namespace Microsoft.AspNetCore.WebSockets
88
{
9+
/// <summary>
10+
/// Extends the <see cref="WebSocketAcceptContext"/> class with additional properties.
11+
/// </summary>
912
public class ExtendedWebSocketAcceptContext : WebSocketAcceptContext
1013
{
14+
/// <inheritdoc />
1115
public override string SubProtocol { get; set; }
1216

17+
/// <summary>
18+
/// This property is obsolete and has no effect.
19+
/// </summary>
1320
[Obsolete("Setting this property has no effect. It will be removed in a future version.")]
1421
public int? ReceiveBufferSize { get; set; }
1522

23+
/// <summary>
24+
/// The interval to send pong frames. This is a heart-beat that keeps the connection alive.
25+
/// </summary>
1626
public TimeSpan? KeepAliveInterval { get; set; }
1727
}
1828
}

src/Middleware/WebSockets/src/Microsoft.AspNetCore.WebSockets.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<Description>ASP.NET Core web socket middleware for use on top of opaque servers.</Description>
@@ -9,6 +9,7 @@
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1010
<PackageTags>aspnetcore</PackageTags>
1111
<IsPackable>false</IsPackable>
12+
<NoWarn>$(NoWarn.Replace('1591', ''))</NoWarn>
1213
</PropertyGroup>
1314

1415
<ItemGroup>

src/Middleware/WebSockets/src/WebSocketMiddleware.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
namespace Microsoft.AspNetCore.WebSockets
1919
{
20+
/// <summary>
21+
/// Enables accepting WebSocket requests by adding a <see cref="IHttpWebSocketFeature"/>
22+
/// to the <see cref="HttpContext"/> if the request is a valid WebSocket request.
23+
/// </summary>
2024
public class WebSocketMiddleware
2125
{
2226
private readonly RequestDelegate _next;
@@ -25,6 +29,12 @@ public class WebSocketMiddleware
2529
private readonly bool _anyOriginAllowed;
2630
private readonly List<string> _allowedOrigins;
2731

32+
/// <summary>
33+
/// Creates a new instance of the <see cref="WebSocketMiddleware"/>.
34+
/// </summary>
35+
/// <param name="next">The next middleware in the pipeline.</param>
36+
/// <param name="options">The configuration options.</param>
37+
/// <param name="loggerFactory">An <see cref="ILoggerFactory"/> instance used to create loggers.</param>
2838
public WebSocketMiddleware(RequestDelegate next, IOptions<WebSocketOptions> options, ILoggerFactory loggerFactory)
2939
{
3040
if (next == null)
@@ -46,6 +56,12 @@ public WebSocketMiddleware(RequestDelegate next, IOptions<WebSocketOptions> opti
4656
// TODO: validate options.
4757
}
4858

59+
/// <summary>
60+
/// Processes a request to determine if it is a WebSocket request, and if so,
61+
/// sets the <see cref="IHttpWebSocketFeature"/> on the <see cref="HttpContext.Features"/>.
62+
/// </summary>
63+
/// <param name="context">The <see cref="HttpContext"/> representing the request.</param>
64+
/// <returns>The <see cref="Task"/> that represents the completion of the middleware pipeline.</returns>
4965
public Task Invoke(HttpContext context)
5066
{
5167
// Detect if an opaque upgrade is available. If so, add a websocket upgrade.

src/Middleware/WebSockets/src/WebSocketOptions.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
namespace Microsoft.AspNetCore.Builder
88
{
99
/// <summary>
10-
/// Configuration options for the WebSocketMiddleware
10+
/// Configuration options for the WebSocketMiddleware.
1111
/// </summary>
1212
public class WebSocketOptions
1313
{
14+
/// <summary>
15+
/// Constructs the <see cref="WebSocketOptions"/> class with default values.
16+
/// </summary>
1417
public WebSocketOptions()
1518
{
1619
KeepAliveInterval = TimeSpan.FromMinutes(2);

src/Middleware/WebSockets/src/WebSocketsDependencyInjectionExtensions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -7,8 +7,17 @@
77

88
namespace Microsoft.AspNetCore.WebSockets
99
{
10+
/// <summary>
11+
/// Extension method for <see cref="IServiceCollection"/> to add WebSockets configuration.
12+
/// </summary>
1013
public static class WebSocketsDependencyInjectionExtensions
1114
{
15+
/// <summary>
16+
/// Extension method for <see cref="IServiceCollection"/> to add WebSockets configuration.
17+
/// </summary>
18+
/// <param name="services">The service collection to add WebSockets specific configuration to.</param>
19+
/// <param name="configure">The configuration callback to setup <see cref="WebSocketOptions"/>.</param>
20+
/// <returns></returns>
1221
public static IServiceCollection AddWebSockets(this IServiceCollection services, Action<WebSocketOptions> configure)
1322
{
1423
return services.Configure(configure);

0 commit comments

Comments
 (0)