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

Is it still correct to use HttpClientHandler in .Net 6? #1961

Closed
jannavarro opened this issue Nov 23, 2022 · 2 comments
Closed

Is it still correct to use HttpClientHandler in .Net 6? #1961

jannavarro opened this issue Nov 23, 2022 · 2 comments

Comments

@jannavarro
Copy link

In .Net Core 2.2 and up the SocketsHttpHandler is the preferred HttpHandler to use when configuring channel options HttpHandler. In fact, .Net 6 documentation always show SocketsHttpHandler as examples in performance best-practices such as setting EnableMultipleHttp2Connections for connection concurrency.

However, what confuses me is if the fact that HttpClientHandler just uses SocketsHttpHandler behind the scenes as seen in this code.

  1. If HttpClientHandler just uses SocketsHttpHandler, is the code below that sets a.HttpHandler = new HttpClientHandler just the same as a.HttpHandler = new SocketsHttpHandler?
                    services.AddCodeFirstGrpcClient<IService>(
                    config =>
                    {
                        config.Address = //URI;

                        config.ChannelOptionsActions.Add(
                            a =>
                            {
                                a.HttpHandler = new HttpClientHandler
                                {
                                    // Do some setup
                                };
                            });
                    });
  1. Since HttpClientHandler just uses SocketsHttpHandler behind the scenes, is there a way to set EnableMultipleHttp2Connections when using just HttpClientHandler just like in the code above?
@JamesNK
Copy link
Member

JamesNK commented Nov 23, 2022

Since HttpClientHandler just uses SocketsHttpHandler behind the scenes, is there a way to set EnableMultipleHttp2Connections when using just HttpClientHandler just like in the code above?

No, there isn't. That's a reason why to prefer SocketsHttpHandler where possible.

@jannavarro
Copy link
Author

@JamesNK thanks for confirming. I understand now that SocketsHttpHandler is still preferred on cases where we need to set EnableMultipleHttp2Connections. I assume the answer to question 1 is also yes. Meaning a.HttpHandler = new HttpClientHandler is equivalent to a.HttpHandler = new SocketsHttpHandler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants