Skip to content

Add SocketsHttpHandler.ConnectCallback #41949

Closed
@geoffkizer

Description

@geoffkizer

Background and Motivation

We recently removed System.Net.Connections from 5.0. One feature we lost was the ConnectionFactory property on SocketsHttpHandler, which allowed you to plug in your own transport that SocketsHttpHandler would run over.

This new API provides the same capability to replace the transport without relying on System.Net.Connections. When you set this property, your callback will be invoked whenever SocketsHttpHandler needs to create a new connection. You can use this callback to create the Stream however you want -- e.g. use an in-memory stream, bind to a particular local address, etc.

Proposed API

public class SocketsHttpHandler
{
    public Func<DnsEndPoint, HttpRequestMessage, CancellationToken, ValueTask<Stream>>? ConnectCallback;
}

The DnsEndPoint argument identifies the server we are trying to connect to. The HttpRequestMessage argument allows you to inspect the initial HttpRequestMessage for this connection -- though you should be aware that the connection can be used for many requests, not just this initial one. We expect most users will only need the DnsEndPoint.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions