Merge branch 'release/3.0-preview8' => 'release/3.0' (#12710)

This commit is contained in:
Doug Bunting 2019-08-03 16:36:55 -07:00 committed by GitHub
commit 9f2b534436
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 75 additions and 4 deletions

View File

@ -221,7 +221,7 @@
<CastleCorePackageVersion>4.2.1</CastleCorePackageVersion>
<FSharpCorePackageVersion>4.2.1</FSharpCorePackageVersion>
<GoogleProtobufPackageVersion>3.8.0</GoogleProtobufPackageVersion>
<GrpcAspNetCorePackageVersion>0.1.22-pre2</GrpcAspNetCorePackageVersion>
<GrpcAspNetCorePackageVersion>0.1.22-pre3</GrpcAspNetCorePackageVersion>
<IdentityServer4AspNetIdentityPackageVersion>3.0.0-preview3.4</IdentityServer4AspNetIdentityPackageVersion>
<IdentityServer4EntityFrameworkPackageVersion>3.0.0-preview3.4</IdentityServer4EntityFrameworkPackageVersion>
<IdentityServer4PackageVersion>3.0.0-preview3.4</IdentityServer4PackageVersion>

View File

@ -15,6 +15,8 @@ namespace GrpcService_CSharp
CreateHostBuilder(args).Build().Run();
}
// Additional configuration is required to successfully run gRPC on macOS.
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>

View File

@ -6,6 +6,7 @@
"SPA"
],
"groupIdentity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.Angular",
"precedence": "5000",
"identity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.Angular.CSharp.3.0",
"name": "ASP.NET Core with Angular",
"preferNameDirectory": true,

View File

@ -6,6 +6,7 @@
"SPA"
],
"groupIdentity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.React",
"precedence": "5000",
"identity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.React.CSharp.3.0",
"name": "ASP.NET Core with React.js",
"preferNameDirectory": true,
@ -189,7 +190,6 @@
"binding": "HostIdentifier"
}
},
"tags": {
"language": "C#",
"type": "project"

View File

@ -6,6 +6,7 @@
"SPA"
],
"groupIdentity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.ReactRedux",
"precedence": "5000",
"identity": "Microsoft.DotNet.Web.Spa.ProjectTemplates.ReactRedux.CSharp.3.0",
"name": "ASP.NET Core with React.js and Redux",
"preferNameDirectory": true,

View File

@ -144,6 +144,7 @@ namespace Microsoft.AspNetCore.SignalR
public HubConnectionContextOptions() { }
public System.TimeSpan ClientTimeoutInterval { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.TimeSpan KeepAliveInterval { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public long? MaximumReceiveMessageSize { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public int StreamBufferCapacity { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
}
public partial class HubConnectionHandler<THub> : Microsoft.AspNetCore.Connections.ConnectionHandler where THub : Microsoft.AspNetCore.SignalR.Hub

View File

@ -43,6 +43,7 @@ namespace Microsoft.AspNetCore.SignalR
private bool _clientTimeoutActive;
private bool _connectionAborted;
private int _streamBufferCapacity;
private long? _maxMessageSize;
/// <summary>
/// Initializes a new instance of the <see cref="HubConnectionContext"/> class.
@ -55,6 +56,7 @@ namespace Microsoft.AspNetCore.SignalR
_keepAliveInterval = contextOptions.KeepAliveInterval.Ticks;
_clientTimeoutInterval = contextOptions.ClientTimeoutInterval.Ticks;
_streamBufferCapacity = contextOptions.StreamBufferCapacity;
_maxMessageSize = contextOptions.MaximumReceiveMessageSize;
_connectionContext = connectionContext;
_logger = loggerFactory.CreateLogger<HubConnectionContext>();
@ -406,10 +408,20 @@ namespace Microsoft.AspNetCore.SignalR
if (!buffer.IsEmpty)
{
if (HandshakeProtocol.TryParseRequestMessage(ref buffer, out var handshakeRequestMessage))
var segment = buffer;
var overLength = false;
if (_maxMessageSize != null && buffer.Length > _maxMessageSize.Value)
{
// We give the parser a sliding window of the default message size
segment = segment.Slice(segment.Start, _maxMessageSize.Value);
overLength = true;
}
if (HandshakeProtocol.TryParseRequestMessage(ref segment, out var handshakeRequestMessage))
{
// We parsed the handshake
consumed = buffer.Start;
consumed = segment.Start;
examined = consumed;
Protocol = protocolResolver.GetProtocol(handshakeRequestMessage.Protocol, supportedProtocols);
@ -461,6 +473,12 @@ namespace Microsoft.AspNetCore.SignalR
await WriteHandshakeResponseAsync(HandshakeResponseMessage.Empty);
return true;
}
else if (overLength)
{
Log.HandshakeSizeLimitExceeded(_logger, _maxMessageSize.Value);
await WriteHandshakeResponseAsync(new HandshakeResponseMessage("Handshake was canceled."));
return false;
}
}
if (result.IsCompleted)
@ -619,6 +637,9 @@ namespace Microsoft.AspNetCore.SignalR
private static readonly Action<ILogger, int, Exception> _clientTimeout =
LoggerMessage.Define<int>(LogLevel.Debug, new EventId(9, "ClientTimeout"), "Client timeout ({ClientTimeout}ms) elapsed without receiving a message from the client. Closing connection.");
private static readonly Action<ILogger, long, Exception> _handshakeSizeLimitExceeded =
LoggerMessage.Define<long>(LogLevel.Debug, new EventId(10, "HandshakeSizeLimitExceeded"), "The maximum message size of {MaxMessageSize}B was exceeded while parsing the Handshake. The message size can be configured in AddHubOptions.");
public static void HandshakeComplete(ILogger logger, string hubProtocol)
{
_handshakeComplete(logger, hubProtocol, null);
@ -663,6 +684,11 @@ namespace Microsoft.AspNetCore.SignalR
{
_clientTimeout(logger, (int)timeout.TotalMilliseconds, null);
}
public static void HandshakeSizeLimitExceeded(ILogger logger, long maxMessageSize)
{
_handshakeSizeLimitExceeded(logger, maxMessageSize, null);
}
}
}
}

View File

@ -24,5 +24,10 @@ namespace Microsoft.AspNetCore.SignalR
/// Gets or sets the max buffer size for client upload streams.
/// </summary>
public int StreamBufferCapacity { get; set; }
/// <summary>
/// Gets or sets the maximum message size the client can send.
/// </summary>
public long? MaximumReceiveMessageSize { get; set; }
}
}

View File

@ -89,6 +89,7 @@ namespace Microsoft.AspNetCore.SignalR
KeepAliveInterval = _hubOptions.KeepAliveInterval ?? _globalHubOptions.KeepAliveInterval ?? HubOptionsSetup.DefaultKeepAliveInterval,
ClientTimeoutInterval = _hubOptions.ClientTimeoutInterval ?? _globalHubOptions.ClientTimeoutInterval ?? HubOptionsSetup.DefaultClientTimeoutInterval,
StreamBufferCapacity = _hubOptions.StreamBufferCapacity ?? _globalHubOptions.StreamBufferCapacity ?? HubOptionsSetup.DefaultStreamBufferCapacity,
MaximumReceiveMessageSize = _maximumMessageSize,
};
Log.ConnectedStarting(_logger);

View File

@ -292,6 +292,40 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
[Fact]
public async Task ConnectionClosedWhenHandshakeLargerThanMaxMessageSize()
{
using (StartVerifiableLog())
{
var connectionHandler = HubConnectionHandlerTestUtils.GetHubConnectionHandler(typeof(HubT), loggerFactory: LoggerFactory,
builder =>
{
builder.AddSignalR(o =>
{
o.MaximumReceiveMessageSize = 1;
});
});
using (var client = new TestClient())
{
client.SupportedFormats = TransferFormat.Text;
var connectionHandlerTask = await client.ConnectAsync(connectionHandler,
sendHandshakeRequestMessage: true,
expectedHandshakeResponseMessage: false);
var message = await client.ReadAsync(isHandshake: true).OrTimeout();
Assert.Equal("Handshake was canceled.", ((HandshakeResponseMessage)message).Error);
// Connection closes
await connectionHandlerTask.OrTimeout();
client.Dispose();
}
}
}
[Fact]
public async Task SendingHandshakeRequestInChunksWorks()
{