Skip to content
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

Remove SocketsHttpConnectionFactory #40075

Closed
scalablecory opened this issue Jul 29, 2020 · 5 comments · Fixed by #40506
Closed

Remove SocketsHttpConnectionFactory #40075

scalablecory opened this issue Jul 29, 2020 · 5 comments · Fixed by #40506
Assignees
Labels
area-System.Net.Http enhancement Product code improvement that does NOT require public API changes/additions
Milestone

Comments

@scalablecory
Copy link
Contributor

SocketsHttpConnectionFactory was proposed as part of #1793.

Its original intent was to provide a number of callbacks for users to customize things without understanding all of the ConnectionFactory stuff. However, API review removed all of these callbacks, making this class largely redundant with SocketsConnectionFactory.

The only remaining features it has are:

  • it pulls the HttpRequestMessage out of the property bag for the user.
  • it turns Nagle off.

We should consider reducing our API surface by doing the following:

  • Remove SocketsHttpConnectionFactory.
  • Update SocketsConnectionFactory to default its sockets with Nagle off.
    • This may cause some confusion to people expecting the default Socket behavior. But, it may be okay to be opinionated here, and most experts end up turning it off anyway.
  • Update the DnsEndPointWithProperties type to expose an HttpRequestMessage property.

Old usage example:

class MyCustomFactory : SocketsHttpConnectionFactory
{
    public override ValueTask<Connection> EstablishConnectionAsync(HttpRequestMessage message, EndPoint endPoint, IConnectionProperties properties, CancellationToken cancellationToken)
    {
       // ...
    }
}

New usage example:

class MyCustomFactory : SocketsConnectionFactory
{
    public override ValueTask<Connection> ConnectAsync(EndPoint endPoint, IConnectionProperties properties, CancellationToken cancellationToken)
    {
        if(!properties.TryGet(out HttpRequestMessage message)) throw new Exception("Expected HttpRequestMessage property");
        // ...
    }
}

CC @geoffkizer @karelz this came about from a discussion with @stephentoub. I feel we can treat this as low priority, but it is a low-effort way to improve API surface.

@scalablecory scalablecory added enhancement Product code improvement that does NOT require public API changes/additions area-System.Net.Http labels Jul 29, 2020
@scalablecory scalablecory added this to the 5.0.0 milestone Jul 29, 2020
@ghost
Copy link

ghost commented Jul 29, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Jul 29, 2020
@karelz karelz removed the untriaged New issue has not been triaged by the area owner label Jul 30, 2020
@geoffkizer
Copy link
Contributor

This seems like a good thing.

But I don't understand this part:

Update the DnsEndPointWithProperties type to expose an HttpRequestMessage property.

@scalablecory
Copy link
Contributor Author

This seems like a good thing.

But I don't understand this part:

Update the DnsEndPointWithProperties type to expose an HttpRequestMessage property.

We currently have this code:

bool IConnectionProperties.TryGet(Type propertyKey, [NotNullWhen(true)] out object? property)
{
if (propertyKey == typeof(DnsEndPointWithProperties))
{
property = this;
return true;
}
property = null;
return false;
}

It exposes a property using an internal type that SocketsHttpConnectionFactory understands. We just need to update this to expose the HttpRequestMessage as a property instead of this internal type.

@geoffkizer
Copy link
Contributor

Yeah, that makes sense, thanks. That seems like it ends up in a better place anyway.

@geoffkizer
Copy link
Contributor

@antonfirsov I believe you're already working on this

@geoffkizer geoffkizer changed the title Consider removing SocketsHttpConnectionFactory Remove SocketsHttpConnectionFactory Aug 6, 2020
@geoffkizer geoffkizer removed their assignment Aug 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Http enhancement Product code improvement that does NOT require public API changes/additions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants