Skip to content

Commit 6a4bca7

Browse files
authored
Add net462 build to Grpc.Net.Client with WinHttpHandler default (#2220)
1 parent a2d005c commit 6a4bca7

28 files changed

+76
-65
lines changed

src/Grpc.Net.Client/Balancer/Internal/ISubchannelTransport.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ internal interface ISubchannelTransport : IDisposable
3333
ValueTask<Stream> GetStreamAsync(BalancerAddress address, CancellationToken cancellationToken);
3434
#endif
3535

36-
#if !NETSTANDARD2_0
36+
#if !NETSTANDARD2_0 && !NET462
3737
ValueTask<ConnectResult>
3838
#else
3939
Task<ConnectResult>

src/Grpc.Net.Client/Balancer/Internal/PassiveSubchannelTransport.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -52,7 +52,7 @@ public void Disconnect()
5252
}
5353

5454
public
55-
#if !NETSTANDARD2_0
55+
#if !NETSTANDARD2_0 && !NET462
5656
ValueTask<ConnectResult>
5757
#else
5858
Task<ConnectResult>
@@ -68,7 +68,7 @@ public void Disconnect()
6868
_currentAddress = currentAddress;
6969
_subchannel.UpdateConnectivityState(ConnectivityState.Ready, "Passively connected.");
7070

71-
#if !NETSTANDARD2_0
71+
#if !NETSTANDARD2_0 && !NET462
7272
return new ValueTask<ConnectResult>(ConnectResult.Success);
7373
#else
7474
return Task.FromResult(ConnectResult.Success);

src/Grpc.Net.Client/Grpc.Net.Client.csproj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66

77
<IsGrpcPublishedPackage>true</IsGrpcPublishedPackage>
88
<GenerateDocumentationFile>true</GenerateDocumentationFile>
9-
<TargetFrameworks>netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
9+
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net5.0;net6.0;net7.0</TargetFrameworks>
1010
<PackageReadmeFile>README.md</PackageReadmeFile>
1111
</PropertyGroup>
1212

13-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
13+
<ItemGroup Condition="'$(TargetFramework)' == 'net462' OR '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netstandard2.1'">
1414
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourcePackageVersion)" />
1515
</ItemGroup>
1616

17+
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
18+
<PackageReference Include="System.Net.Http.WinHttpHandler" Version="$(SystemNetHttpWinHttpHandlerPackageVersion)" />
19+
</ItemGroup>
20+
1721
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net7.0'">
1822
<DefineConstants>SUPPORT_LOAD_BALANCING;$(DefineConstants)</DefineConstants>
1923
</PropertyGroup>

src/Grpc.Net.Client/GrpcChannel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ private static HttpHandlerContext CalculateHandlerContext(ILogger logger, Uri ad
230230
{
231231
// No way to know what handler a HttpClient is using so assume custom.
232232
var type = channelOptions.HttpClient == null
233+
#if NET462
234+
? HttpHandlerType.WinHttpHandler
235+
#else
233236
? HttpHandlerType.SocketsHttpHandler
237+
#endif
234238
: HttpHandlerType.Custom;
235239

236240
return new HttpHandlerContext(type);

src/Grpc.Net.Client/Internal/ArrayBufferWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -18,7 +18,7 @@
1818

1919
using System.Diagnostics;
2020

21-
#if NETSTANDARD2_0
21+
#if NETSTANDARD2_0 || NET462
2222

2323
// Copied with permission from https://github.com/dotnet/runtime/blob/589d0dc326bf0699149f76033fa66d4b22b9a7fd/src/libraries/Common/src/System/Buffers/ArrayBufferWriter.cs
2424
// This copy of ArrayBufferWriter is only used with .NET Stardard 2.0. Later versions of .NET ship with this type.
@@ -227,4 +227,4 @@ private static void ThrowOutOfMemoryException(uint capacity)
227227
}
228228
}
229229

230-
#endif
230+
#endif

src/Grpc.Net.Client/Internal/GrpcCall.NonGeneric.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ private static StatusCode MapHttpStatusToGrpcCode(HttpStatusCode httpStatusCode)
193193
switch (httpStatusCode)
194194
{
195195
case HttpStatusCode.BadRequest: // 400
196-
#if !NETSTANDARD2_0
196+
#if !NETSTANDARD2_0 && !NET462
197197
case HttpStatusCode.RequestHeaderFieldsTooLarge: // 431
198198
#else
199199
case (HttpStatusCode)431:
@@ -205,7 +205,7 @@ private static StatusCode MapHttpStatusToGrpcCode(HttpStatusCode httpStatusCode)
205205
return StatusCode.PermissionDenied;
206206
case HttpStatusCode.NotFound: // 404
207207
return StatusCode.Unimplemented;
208-
#if !NETSTANDARD2_0
208+
#if !NETSTANDARD2_0 && !NET462
209209
case HttpStatusCode.TooManyRequests: // 429
210210
#else
211211
case (HttpStatusCode)429:

src/Grpc.Net.Client/Internal/GrpcCall.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
using Grpc.Net.Client.Balancer.Internal;
2929
#endif
3030

31-
#if NETSTANDARD2_0
31+
#if NETSTANDARD2_0 || NET462
3232
using ValueTask = System.Threading.Tasks.Task;
3333
#endif
3434

@@ -1116,7 +1116,7 @@ internal ValueTask WriteMessageAsync(
11161116
callOptions);
11171117
}
11181118

1119-
#if !NETSTANDARD2_0
1119+
#if !NETSTANDARD2_0 && !NET462
11201120
internal async ValueTask<TResponse?> ReadMessageAsync(
11211121
#else
11221122
internal async Task<TResponse?> ReadMessageAsync(

src/Grpc.Net.Client/Internal/GrpcCallSerializationContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -295,7 +295,7 @@ private ReadOnlySpan<byte> CompressMessage(ReadOnlySpan<byte> messageData)
295295
// GZipStream writes final Adler32 at the end of the stream on dispose.
296296
using (var compressionStream = _compressionProvider.CreateCompressionStream(output, CompressionLevel.Fastest))
297297
{
298-
#if !NETSTANDARD2_0
298+
#if !NETSTANDARD2_0 && !NET462
299299
compressionStream.Write(messageData);
300300
#else
301301
var array = messageData.ToArray();

src/Grpc.Net.Client/Internal/GrpcEventSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -27,7 +27,7 @@ internal sealed class GrpcEventSource : EventSource
2727
{
2828
public static readonly GrpcEventSource Log = new GrpcEventSource();
2929

30-
#if !NETSTANDARD2_0
30+
#if !NETSTANDARD2_0 && !NET462
3131
private PollingCounter? _totalCallsCounter;
3232
private PollingCounter? _currentCallsCounter;
3333
private PollingCounter? _messagesSentCounter;
@@ -146,7 +146,7 @@ protected override void OnEventCommand(EventCommandEventArgs command)
146146
// This is the convention for initializing counters in the RuntimeEventSource (lazily on the first enable command).
147147
// They aren't disabled afterwards...
148148

149-
#if !NETSTANDARD2_0
149+
#if !NETSTANDARD2_0 && !NET462
150150
_totalCallsCounter ??= new PollingCounter("total-calls", this, () => Volatile.Read(ref _totalCalls))
151151
{
152152
DisplayName = "Total Calls",

src/Grpc.Net.Client/Internal/GrpcProtocolConstants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Copyright notice and license
1+
#region Copyright notice and license
22

33
// Copyright 2019 The gRPC Authors
44
//
@@ -24,7 +24,7 @@ namespace Grpc.Net.Client.Internal;
2424

2525
internal static class GrpcProtocolConstants
2626
{
27-
#if !NETSTANDARD2_0
27+
#if !NETSTANDARD2_0 && !NET462
2828
public static readonly Version Http2Version = System.Net.HttpVersion.Version20;
2929
#else
3030
public static readonly Version Http2Version = new Version(2, 0);
@@ -76,7 +76,7 @@ internal static class GrpcProtocolConstants
7676
internal static string GetMessageAcceptEncoding(Dictionary<string, ICompressionProvider> compressionProviders)
7777
{
7878
return IdentityGrpcEncoding + "," +
79-
#if !NETSTANDARD2_0
79+
#if !NETSTANDARD2_0 && !NET462
8080
string.Join(',', compressionProviders.Select(p => p.Key));
8181
#else
8282
string.Join(",", compressionProviders.Select(p => p.Key));

0 commit comments

Comments
 (0)