Skip to content

Upgrade Kestrel to target netcoreapp3.0 #4405

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

Merged
merged 1 commit into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/Servers/Kestrel/Core/src/Adapter/Internal/AdaptedPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,27 +74,13 @@ private async Task WriteOutputAsync(Stream stream)
}
else if (buffer.IsSingleSegment)
{
#if NETCOREAPP2_1
await stream.WriteAsync(buffer.First);
#elif NETSTANDARD2_0
var array = buffer.First.GetArray();
await stream.WriteAsync(array.Array, array.Offset, array.Count);
#else
#error TFMs need to be updated
#endif
}
else
{
foreach (var memory in buffer)
{
#if NETCOREAPP2_1
await stream.WriteAsync(memory);
#elif NETSTANDARD2_0
var array = memory.GetArray();
await stream.WriteAsync(array.Array, array.Offset, array.Count);
#else
#error TFMs need to be updated
#endif
}
}
}
Expand Down Expand Up @@ -131,14 +117,7 @@ private async Task ReadInputAsync(Stream stream)
{

var outputBuffer = Input.Writer.GetMemory(MinAllocBufferSize);
#if NETCOREAPP2_1
var bytesRead = await stream.ReadAsync(outputBuffer);
#elif NETSTANDARD2_0
var array = outputBuffer.GetArray();
var bytesRead = await stream.ReadAsync(array.Array, array.Offset, array.Count);
#else
#error TFMs need to be updated
#endif
Input.Writer.Advance(bytesRead);

if (bytesRead == 0)
Expand Down
20 changes: 0 additions & 20 deletions src/Servers/Kestrel/Core/src/Adapter/Internal/LoggingStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,12 @@ public override int Read(byte[] buffer, int offset, int count)
return read;
}

#if NETCOREAPP2_1
public override int Read(Span<byte> destination)
{
int read = _inner.Read(destination);
Log("Read", destination.Slice(0, read));
return read;
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override async ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{
int read = await _inner.ReadAsync(destination, cancellationToken);
Log("ReadAsync", destination.Span.Slice(0, read));
return read;
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override void Write(ReadOnlySpan<byte> source)
{
Log("Write", source);
_inner.Write(source);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
Log("WriteAsync", source.Span);
return _inner.WriteAsync(source, cancellationToken);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

private void Log(string method, ReadOnlySpan<byte> buffer)
{
Expand Down
10 changes: 0 additions & 10 deletions src/Servers/Kestrel/Core/src/Adapter/Internal/RawStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,10 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
return ReadAsyncInternal(new Memory<byte>(buffer, offset, count)).AsTask();
}

#if NETCOREAPP2_1
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{
return ReadAsyncInternal(destination);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override async ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
_output.Write(source.Span);
await _output.FlushAsync(cancellationToken);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

public override void Flush()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,12 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
return ReadAsyncInternal(new Memory<byte>(buffer, offset, count), cancellationToken).AsTask();
}

#if NETCOREAPP2_1
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{
ValidateState(cancellationToken);

return ReadAsyncInternal(destination, cancellationToken);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

private async ValueTask<int> ReadAsyncInternal(Memory<byte> buffer, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,12 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
return _httpResponseControl.WriteAsync(new ReadOnlyMemory<byte>(buffer, offset, count), cancellationToken);
}

#if NETCOREAPP2_1
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
ValidateState(cancellationToken);

return new ValueTask(_httpResponseControl.WriteAsync(source, cancellationToken));
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

public void StartAcceptingWrites()
{
Expand Down
10 changes: 0 additions & 10 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpUpgradeStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,10 @@ public override Task<int> ReadAsync(byte[] buffer, int offset, int count, Cancel
return _requestStream.ReadAsync(buffer, offset, count, cancellationToken);
}

#if NETCOREAPP2_1
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
{
return _requestStream.ReadAsync(destination, cancellationToken);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
{
return _responseStream.WriteAsync(source, cancellationToken);
}
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

public override long Seek(long offset, SeekOrigin origin)
{
Expand Down
8 changes: 0 additions & 8 deletions src/Servers/Kestrel/Core/src/Internal/Http/MessageBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,7 @@ protected MessageBody(HttpProtocol context, MinDataRate minRequestBodyDataRate)
// REVIEW: This *could* be slower if 2 things are true
// - The WriteAsync(ReadOnlyMemory<byte>) isn't overridden on the destination
// - We change the Kestrel Memory Pool to not use pinned arrays but instead use native memory

#if NETCOREAPP2_1
await destination.WriteAsync(memory, cancellationToken);
#elif NETSTANDARD2_0
var array = memory.GetArray();
await destination.WriteAsync(array.Array, array.Offset, array.Count, cancellationToken);
#else
#error TFMs need to be updated
#endif
}
}

Expand Down
22 changes: 0 additions & 22 deletions src/Servers/Kestrel/Core/src/Internal/HttpsConnectionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ private async Task<IAdaptedConnection> InnerOnConnectionAsync(ConnectionAdapterC

try
{
#if NETCOREAPP2_1
// Adapt to the SslStream signature
ServerCertificateSelectionCallback selector = null;
if (_serverCertificateSelector != null)
Expand Down Expand Up @@ -172,22 +171,6 @@ private async Task<IAdaptedConnection> InnerOnConnectionAsync(ConnectionAdapterC
}

await sslStream.AuthenticateAsServerAsync(sslOptions, CancellationToken.None);
#elif NETSTANDARD2_0 // No ALPN support
var serverCert = _serverCertificate;
if (_serverCertificateSelector != null)
{
context.Features.Set(sslStream);
serverCert = _serverCertificateSelector(context.ConnectionContext, null);
if (serverCert != null)
{
EnsureCertificateIsAllowedForServerAuth(serverCert);
}
}
await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired,
_options.SslProtocols, _options.CheckCertificateRevocation);
#else
#error TFMs need to be updated
#endif
}
catch (OperationCanceledException)
{
Expand All @@ -206,13 +189,8 @@ await sslStream.AuthenticateAsServerAsync(serverCert, certificateRequired,
timeoutFeature.CancelTimeout();
}

#if NETCOREAPP2_1
feature.ApplicationProtocol = sslStream.NegotiatedApplicationProtocol.Protocol;
context.Features.Set<ITlsApplicationProtocolFeature>(feature);
#elif NETSTANDARD2_0 // No ALPN support
#else
#error TFMs need to be updated
#endif
feature.ClientCertificate = ConvertToX509Certificate2(sslStream.RemoteCertificate);
feature.CipherAlgorithm = sslStream.CipherAlgorithm;
feature.CipherStrength = sslStream.CipherStrength;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

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

#if NETCOREAPP2_1
public override ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken cancellationToken = default)
=> _inner.ReadAsync(destination, cancellationToken);
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

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

#if NETCOREAPP2_1
public override ValueTask WriteAsync(ReadOnlyMemory<byte> source, CancellationToken cancellationToken = default)
=> _inner.WriteAsync(source, cancellationToken);
#elif NETSTANDARD2_0
#else
#error TFMs need to be updated
#endif

public override void WriteByte(byte value)
=> _inner.WriteByte(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Core components of ASP.NET Core Kestrel cross-platform web server.</Description>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;kestrel</PackageTags>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
Expand Down
14 changes: 1 addition & 13 deletions src/Servers/Kestrel/Core/test/HttpRequestStreamTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

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

#if NET461
[Fact]
public void BeginWriteThrows()
{
var stream = new HttpRequestStream(Mock.Of<IHttpBodyControlFeature>());
Assert.Throws<NotSupportedException>(() => stream.BeginWrite(new byte[1], 0, 1, null, null));
}
#elif NETCOREAPP2_2
#else
#error Target framework needs to be updated
#endif

[Fact]
// Read-only streams should support Flush according to https://github.com/dotnet/corefx/pull/27327#pullrequestreview-98384813
public void FlushDoesNotThrow()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>ASP.NET Core Kestrel cross-platform web server.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;kestrel</PackageTags>
<NoWarn>CS1591;$(NoWarn)</NoWarn>
Expand Down
7 changes: 1 addition & 6 deletions src/Servers/Kestrel/Kestrel/test/GeneratedCodeTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

#if NETCOREAPP2_2
using System;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -57,7 +56,3 @@ public void GeneratedCodeIsUpToDate()
}
}
}
#elif NET461
#else
#error Target framework needs to be updated
#endif
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp2.2;net461</TargetFrameworks>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>Transport abstractions for the ASP.NET Core Kestrel cross-platform web server.</Description>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;kestrel</PackageTags>
<NoWarn>CS1570;CS1571;CS1572;CS1573;CS1574;CS1591;$(NoWarn)</NoWarn>
Expand Down
Loading