-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Description
Background and Motivation
We recently added WebSockets over HTTP/2 support to Kestrel. By default this lights up automatically if your app supports HTTP/2 and you use the browser. One potential problem is that using WebSockets with controllers could potentially stop working because WebSockets over HTTP/2 now uses a CONNECT request instead of a GET request.
Our docs even show using WebSockets from a controller and are now broken in this specific scenario.
Proposed API
namespace Microsoft.AspNetCore.Mvc;
+ public class HttpConnectAttribute : HttpMethodAttribute
+ {
+ public HttpConnectAttribute();
+ public HttpConnectAttribute([StringSyntax("Route")] string template);
+ }Usage Examples
public class WebSocketController : ControllerBase
{
[HttpGet("/ws")]
[HttpConnect("/ws")]
public async Task Get()
{
if (HttpContext.WebSockets.IsWebSocketRequest)
{
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
await Echo(webSocket);
}
else
{
HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
}
}
}Alternative Designs
public class WebSocketController : ControllerBase
{
[WebSocket("/ws")]
public async Task Get()
{
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
await Echo(webSocket);
}
}Don't add a new API and add docs to show using a custom HttpMethodAttribute.
Risks
Metadata
Metadata
Assignees
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels