Skip to content

Expose Socket via a Kestrel ConnectionContext feature #28401

Closed
@halter73

Description

@halter73

Is your feature request related to a problem? Please describe.

We should make it so you don't have to resort to something like the following to access the managed Socket if you really want to.

var socket = (Socket)connectionContext.GetType().GetField("_socket", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(connectionContext);

Proposed API

using System.Net.Sockets;

namespace Microsoft.AspNetCore.Connections.Features
{
+    public interface IConnectionSocketFeature
+   {
+        Socket? Socket { get; }
+    }
}

Usage Examples

var socket = connectionContext.Features.Get<IConnectionSocketFeature>().Socket;

Metadata

Metadata

Assignees

Labels

affected-very-fewThis issue impacts very few customersapi-approvedAPI was approved in API review, it can be implementedarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-kestrelhelp wantedUp for grabs. We would accept a PR to help resolve this issueseverity-nice-to-haveThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions