Skip to content

Implement IConnectionEndPointFeature in Kestrel's TransportConnection #62162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 29, 2025

This PR implements IConnectionEndPointFeature in Kestrel's TransportConnection class to address the issue where this feature was only available in test scenarios via DefaultConnectionContext.

Background

IConnectionEndPointFeature was added as part of bedrock in #10321 but was only implemented in DefaultConnectionContext, which is primarily used by test projects. This meant that production Kestrel connections couldn't access endpoint information through the standard feature interface.

Changes

The implementation adds IConnectionEndPointFeature support to TransportConnection by:

  1. Adding the feature to code generation configuration - Updated TransportConnectionFeatureCollection.cs to include IConnectionEndPointFeature in both allFeatures and implementedFeatures arrays
  2. Regenerating feature collection code - Used the existing code generator to update TransportConnection.Generated.cs with the new feature support
  3. Implementing the feature interface - Added implementation methods in TransportConnection.FeatureCollection.cs that delegate to the existing LocalEndPoint and RemoteEndPoint properties

Usage

After this change, applications can access connection endpoints through the feature interface:

var endpointFeature = connectionContext.Features.Get<IConnectionEndPointFeature>();
var localEndpoint = endpointFeature?.LocalEndPoint;
var remoteEndpoint = endpointFeature?.RemoteEndPoint;

This maintains full compatibility with existing code that uses the direct properties while providing the standard feature interface for consistency with other ASP.NET Core components.

Impact

  • Minimal changes: Only 3 files modified with 41 additions and 3 deletions
  • No breaking changes: Existing code continues to work unchanged
  • Consistent API: Provides the same endpoint access pattern used elsewhere in ASP.NET Core
  • Production ready: Makes the feature available in real Kestrel connections, not just tests

Fixes #43786.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] What are we doing with IConnectionEndPointFeature Implement IConnectionEndPointFeature in Kestrel's TransportConnection May 29, 2025
@Copilot Copilot AI requested a review from BrennanConroy May 29, 2025 20:43
Copilot finished work on behalf of BrennanConroy May 29, 2025 20:43
@BrennanConroy
Copy link
Member

Looking good, can you add a test that verifies the feature is in the feature collection and has values?

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented May 30, 2025

Looking good, can you add a test that verifies the feature is in the feature collection and has values?

Added comprehensive tests in TransportConnectionFeatureCollectionTests.cs that verify IConnectionEndPointFeature is available in the feature collection and properly returns/sets endpoint values. The tests follow existing patterns and validate both getting and setting LocalEndPoint and RemoteEndPoint through the feature interface. (dbd9f49)

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of BrennanConroy May 30, 2025 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What are we doing with IConnectionEndPointFeature
2 participants