Skip to content

Commit af709dd

Browse files
authored
Check SocketsHttpHandler.IsSupported before creating handler (#1030)
1 parent 5faaabe commit af709dd

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/Grpc.Net.Client/GrpcChannel.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,17 @@ private static HttpMessageInvoker CreateInternalHttpInvoker(HttpMessageHandler?
101101
if (handler == null)
102102
{
103103
#if NET5_0
104-
handler = new SocketsHttpHandler
104+
if (SocketsHttpHandler.IsSupported)
105105
{
106-
EnableMultipleHttp2Connections = true
107-
};
106+
handler = new SocketsHttpHandler
107+
{
108+
EnableMultipleHttp2Connections = true
109+
};
110+
}
111+
else
112+
{
113+
handler = new HttpClientHandler();
114+
}
108115
#else
109116
handler = new HttpClientHandler();
110117
#endif
@@ -120,6 +127,8 @@ private static HttpMessageInvoker CreateInternalHttpInvoker(HttpMessageHandler?
120127
}
121128
#endif
122129

130+
// Use HttpMessageInvoker instead of HttpClient because it is faster
131+
// and we don't need client's features.
123132
var httpInvoker = new HttpMessageInvoker(handler, disposeHandler: true);
124133

125134
return httpInvoker;

0 commit comments

Comments
 (0)