Skip to content

Commit e1e809b

Browse files
committed
Upgrade Kestrel to target netcoreapp3.0 #3754
1 parent 6fc7e53 commit e1e809b

File tree

41 files changed

+41
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+41
-243
lines changed

src/Servers/Kestrel/Core/src/Adapter/Internal/AdaptedPipeline.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,13 @@ private async Task WriteOutputAsync(Stream stream)
7474
}
7575
else if (buffer.IsSingleSegment)
7676
{
77-
#if NETCOREAPP2_1
7877
await stream.WriteAsync(buffer.First);
79-
#elif NETSTANDARD2_0
80-
var array = buffer.First.GetArray();
81-
await stream.WriteAsync(array.Array, array.Offset, array.Count);
82-
#else
83-
#error TFMs need to be updated
84-
#endif
8578
}
8679
else
8780
{
8881
foreach (var memory in buffer)
8982
{
90-
#if NETCOREAPP2_1
9183
await stream.WriteAsync(memory);
92-
#elif NETSTANDARD2_0
93-
var array = memory.GetArray();
94-
await stream.WriteAsync(array.Array, array.Offset, array.Count);
95-
#else
96-
#error TFMs need to be updated
97-
#endif
9884
}
9985
}
10086
}
@@ -131,14 +117,7 @@ private async Task ReadInputAsync(Stream stream)
131117
{
132118

133119
var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize);
134-
#if NETCOREAPP2_1
135120
var bytesRead = await stream.ReadAsync(outputBuffer);
136-
#elif NETSTANDARD2_0
137-
var array = outputBuffer.GetArray();
138-
var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count);
139-
#else
140-
#error TFMs need to be updated
141-
#endif
142121
Input.Writer.Advance(bytesRead);
143122

144123
if (bytesRead == 0)

src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingStream.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,12 @@ public override int Read(byte[] buffer, int offset, int count)
8383
return read;
8484
}
8585

86-
#if NETCOREAPP2_1
8786
public override int Read(Span<byte> destination)
8887
{
8988
int read = _inner.Read(destination);
9089
Log("Read", destination.Slice(0, read));
9190
return read;
9291
}
93-
#elif NETSTANDARD2_0
94-
#else
95-
#error TFMs need to be updated
96-
#endif
9792

9893
public async override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
9994
{
@@ -102,17 +97,12 @@ public async override Task<int> ReadAsync(byte[] buffer, int offset, int count,
10297
return read;
10398
}
10499

105-
#if NETCOREAPP2_1
106100
public override async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
107101
{
108102
int read = await _inner.ReadAsync(destination, cancellationToken);
109103
Log("ReadAsync", destination.Span.Slice(0, read));
110104
return read;
111105
}
112-
#elif NETSTANDARD2_0
113-
#else
114-
#error TFMs need to be updated
115-
#endif
116106

117107
public override long Seek(long offset, SeekOrigin origin)
118108
{
@@ -130,33 +120,23 @@ public override void Write(byte[] buffer, int offset, int count)
130120
_inner.Write(buffer, offset, count);
131121
}
132122

133-
#if NETCOREAPP2_1
134123
public override void Write(ReadOnlySpan<byte> source)
135124
{
136125
Log("Write", source);
137126
_inner.Write(source);
138127
}
139-
#elif NETSTANDARD2_0
140-
#else
141-
#error TFMs need to be updated
142-
#endif
143128

144129
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
145130
{
146131
Log("WriteAsync", new ReadOnlySpan<byte>(buffer, offset, count));
147132
return _inner.WriteAsync(buffer, offset, count, cancellationToken);
148133
}
149134

150-
#if NETCOREAPP2_1
151135
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
152136
{
153137
Log("WriteAsync", source.Span);
154138
return _inner.WriteAsync(source, cancellationToken);
155139
}
156-
#elif NETSTANDARD2_0
157-
#else
158-
#error TFMs need to be updated
159-
#endif
160140

161141
private void Log(string method, ReadOnlySpan<byte> buffer)
162142
{

src/Servers/Kestrel/Core/src/Adapter/Internal/RawStream.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,10 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
6969
return ReadAsyncInternal(new Memory<byte>(buffer, offset, count)).AsTask();
7070
}
7171

72-
#if NETCOREAPP2_1
7372
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
7473
{
7574
return ReadAsyncInternal(destination);
7675
}
77-
#elif NETSTANDARD2_0
78-
#else
79-
#error TFMs need to be updated
80-
#endif
8176

8277
public override void Write(byte[] buffer, int offset, int count)
8378
{
@@ -94,16 +89,11 @@ public override async Task WriteAsync(byte[] buffer, int offset, int count, Canc
9489
await _output.FlushAsync(cancellationToken);
9590
}
9691

97-
#if NETCOREAPP2_1
9892
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
9993
{
10094
_output.Write(source.Span);
10195
await _output.FlushAsync(cancellationToken);
10296
}
103-
#elif NETSTANDARD2_0
104-
#else
105-
#error TFMs need to be updated
106-
#endif
10797

10898
public override void Flush()
10999
{

src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestStream.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,12 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
111111
return ReadAsyncInternal(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
112112
}
113113

114-
#if NETCOREAPP2_1
115114
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
116115
{
117116
ValidateState(cancellationToken);
118117

119118
return ReadAsyncInternal(destination, cancellationToken);
120119
}
121-
#elif NETSTANDARD2_0
122-
#else
123-
#error TFMs need to be updated
124-
#endif
125120

126121
private async ValueTask<int> ReadAsyncInternal(Memory<byte> buffer, CancellationToken cancellationToken)
127122
{

src/Servers/Kestrel/Core/src/Internal/Http/HttpResponseStream.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,17 +112,12 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
112112
return _httpResponseControl.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
113113
}
114114

115-
#if NETCOREAPP2_1
116115
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
117116
{
118117
ValidateState(cancellationToken);
119118

120119
return new ValueTask(_httpResponseControl.WriteAsync(source, cancellationToken));
121120
}
122-
#elif NETSTANDARD2_0
123-
#else
124-
#error TFMs need to be updated
125-
#endif
126121

127122
public void StartAcceptingWrites()
128123
{

src/Servers/Kestrel/Core/src/Internal/Http/HttpUpgradeStream.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,10 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
145145
return _requestStream.ReadAsync(buffer, offset, count, cancellationToken);
146146
}
147147

148-
#if NETCOREAPP2_1
149148
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
150149
{
151150
return _requestStream.ReadAsync(destination, cancellationToken);
152151
}
153-
#elif NETSTANDARD2_0
154-
#else
155-
#error TFMs need to be updated
156-
#endif
157152

158153
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
159154
{
@@ -165,15 +160,10 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
165160
return _responseStream.WriteAsync(buffer, offset, count, cancellationToken);
166161
}
167162

168-
#if NETCOREAPP2_1
169163
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
170164
{
171165
return _responseStream.WriteAsync(source, cancellationToken);
172166
}
173-
#elif NETSTANDARD2_0
174-
#else
175-
#error TFMs need to be updated
176-
#endif
177167

178168
public override long Seek(long offset, SeekOrigin origin)
179169
{

src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,7 @@ protected MessageBody(HttpProtocol context, MinDataRate minRequestBodyDataRate)
113113
// REVIEW: This *could* be slower if 2 things are true
114114
// - The WriteAsync(ReadOnlyMemory<byte>) isn't overridden on the destination
115115
// - We change the Kestrel Memory Pool to not use pinned arrays but instead use native memory
116-
117-
#if NETCOREAPP2_1
118116
await destination.WriteAsync(memory, cancellationToken);
119-
#elif NETSTANDARD2_0
120-
var array = memory.GetArray();
121-
await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken);
122-
#else
123-
#error TFMs need to be updated
124-
#endif
125117
}
126118
}
127119

src/Servers/Kestrel/Core/src/Internal/HttpsConnectionAdapter.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ private async Task<IAdaptedConnection> InnerOnConnectionAsync(ConnectionAdapterC
131131

132132
try
133133
{
134-
#if NETCOREAPP2_1
135134
// Adapt to the SslStream signature
136135
ServerCertificateSelectionCallback selector = null;
137136
if (_serverCertificateSelector != null)
@@ -172,22 +171,6 @@ private async Task<IAdaptedConnection> InnerOnConnectionAsync(ConnectionAdapterC
172171
}
173172

174173
await sslStream.AuthenticateAsServerAsync(sslOptions, CancellationToken.None);
175-
#elif NETSTANDARD2_0 // No ALPN support
176-
var serverCert = _serverCertificate;
177-
if (_serverCertificateSelector != null)
178-
{
179-
context.Features.Set(sslStream);
180-
serverCert = _serverCertificateSelector(context.ConnectionContext, null);
181-
if (serverCert != null)
182-
{
183-
EnsureCertificateIsAllowedForServerAuth(serverCert);
184-
}
185-
}
186-
await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired,
187-
_options.SslProtocols, _options.CheckCertificateRevocation);
188-
#else
189-
#error TFMs need to be updated
190-
#endif
191174
}
192175
catch (OperationCanceledException)
193176
{
@@ -206,13 +189,8 @@ await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired,
206189
timeoutFeature.CancelTimeout();
207190
}
208191

209-
#if NETCOREAPP2_1
210192
feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol;
211193
context.Features.Set<ITlsApplicationProtocolFeature>(feature);
212-
#elif NETSTANDARD2_0 // No ALPN support
213-
#else
214-
#error TFMs need to be updated
215-
#endif
216194
feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate);
217195
feature.CipherAlgorithm = sslStream.CipherAlgorithm;
218196
feature.CipherStrength = sslStream.CipherStrength;

src/Servers/Kestrel/Core/src/Internal/Infrastructure/WrappingStream.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -68,13 +68,8 @@ public override int Read(byte[] buffer, int offset, int count)
6868
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
6969
=> _inner.ReadAsync(buffer, offset, count, cancellationToken);
7070

71-
#if NETCOREAPP2_1
7271
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
7372
=> _inner.ReadAsync(destination, cancellationToken);
74-
#elif NETSTANDARD2_0
75-
#else
76-
#error TFMs need to be updated
77-
#endif
7873

7974
public override int ReadByte()
8075
=> _inner.ReadByte();
@@ -91,13 +86,8 @@ public override void Write(byte[] buffer, int offset, int count)
9186
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
9287
=> _inner.WriteAsync(buffer, offset, count, cancellationToken);
9388

94-
#if NETCOREAPP2_1
9589
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
9690
=> _inner.WriteAsync(source, cancellationToken);
97-
#elif NETSTANDARD2_0
98-
#else
99-
#error TFMs need to be updated
100-
#endif
10191

10292
public override void WriteByte(byte value)
10393
=> _inner.WriteByte(value);

src/Servers/Kestrel/Core/src/Microsoft.AspNetCore.Server.Kestrel.Core.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Core components of ASP.NET Core Kestrel cross-platform web server.</Description>
5-
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;kestrel</PackageTags>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -85,18 +85,6 @@ public async Task WriteAsyncThrows()
8585
await Assert.ThrowsAsync<NotSupportedException>(() => stream.WriteAsync(new byte[1], 0, 1));
8686
}
8787

88-
#if NET461
89-
[Fact]
90-
public void BeginWriteThrows()
91-
{
92-
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>());
93-
Assert.Throws<NotSupportedException>(() => stream.BeginWrite(new byte[1], 0, 1, null, null));
94-
}
95-
#elif NETCOREAPP2_2
96-
#else
97-
#error Target framework needs to be updated
98-
#endif
99-
10088
[Fact]
10189
// Read-only streams should support Flush according to https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813
10290
public void FlushDoesNotThrow()

src/Servers/Kestrel/Core/test/Microsoft.AspNetCore.Server.Kestrel.Core.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
66
</PropertyGroup>
77

src/Servers/Kestrel/Kestrel/src/Microsoft.AspNetCore.Server.Kestrel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>ASP.NET Core Kestrel cross-platform web server.</Description>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;kestrel</PackageTags>
88
<NoWarn>CS1591;$(NoWarn)</NoWarn>

src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
#if NETCOREAPP2_2
54
using System;
65
using System.IO;
76
using System.Linq;
@@ -57,7 +56,3 @@ public void GeneratedCodeIsUpToDate()
5756
}
5857
}
5958
}
60-
#elif NET461
61-
#else
62-
#error Target framework needs to be updated
63-
#endif

src/Servers/Kestrel/Kestrel/test/Microsoft.AspNetCore.Server.Kestrel.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

src/Servers/Kestrel/Transport.Abstractions/src/Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>Transport abstractions for the ASP.NET Core Kestrel cross-platform web server.</Description>
5-
<TargetFramework>netstandard2.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
77
<PackageTags>aspnetcore;kestrel</PackageTags>
88
<NoWarn>CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn)</NoWarn>

0 commit comments

Comments
 (0)