From 10dc6e3bdc6319c1d9537364f7e1e75e6f28be17 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Mon, 22 Apr 2019 11:35:18 -0700 Subject: [PATCH] Custom hub options don't change global hub options (#9638) --- .../server/Core/src/Internal/HubOptionsSetup.cs | 2 +- .../Core/src/Internal/HubOptionsSetup`T.cs | 9 +++++++-- .../server/SignalR/test/AddSignalRTests.cs | 17 ++++++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/SignalR/server/Core/src/Internal/HubOptionsSetup.cs b/src/SignalR/server/Core/src/Internal/HubOptionsSetup.cs index de98df4c60..0692a4a74b 100644 --- a/src/SignalR/server/Core/src/Internal/HubOptionsSetup.cs +++ b/src/SignalR/server/Core/src/Internal/HubOptionsSetup.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal internal static TimeSpan DefaultClientTimeoutInterval => TimeSpan.FromSeconds(30); - internal const int DefaultMaximumMessageSize = 32 * 1024 * 1024; + internal const int DefaultMaximumMessageSize = 32 * 1024; private readonly List _defaultProtocols = new List(); diff --git a/src/SignalR/server/Core/src/Internal/HubOptionsSetup`T.cs b/src/SignalR/server/Core/src/Internal/HubOptionsSetup`T.cs index 8a82d6b48e..f55810dd03 100644 --- a/src/SignalR/server/Core/src/Internal/HubOptionsSetup`T.cs +++ b/src/SignalR/server/Core/src/Internal/HubOptionsSetup`T.cs @@ -1,6 +1,7 @@ -// 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.Collections.Generic; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.SignalR.Internal @@ -15,7 +16,11 @@ namespace Microsoft.AspNetCore.SignalR.Internal public void Configure(HubOptions options) { - options.SupportedProtocols = _hubOptions.SupportedProtocols; + options.SupportedProtocols = new List(_hubOptions.SupportedProtocols.Count); + foreach (var protocol in _hubOptions.SupportedProtocols) + { + options.SupportedProtocols.Add(protocol); + } options.KeepAliveInterval = _hubOptions.KeepAliveInterval; options.HandshakeTimeout = _hubOptions.HandshakeTimeout; } diff --git a/src/SignalR/server/SignalR/test/AddSignalRTests.cs b/src/SignalR/server/SignalR/test/AddSignalRTests.cs index f5e15fb0b0..325c293826 100644 --- a/src/SignalR/server/SignalR/test/AddSignalRTests.cs +++ b/src/SignalR/server/SignalR/test/AddSignalRTests.cs @@ -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.Collections.Generic; @@ -65,6 +65,21 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.IsType>(serviceProvider.GetRequiredService>()); Assert.IsType>(serviceProvider.GetRequiredService>()); } + + [Fact] + public void HubSpecificOptionsDoNotAffectGlobalHubOptions() + { + var serviceCollection = new ServiceCollection(); + + serviceCollection.AddSignalR().AddHubOptions(options => + { + options.SupportedProtocols.Clear(); + }); + + var serviceProvider = serviceCollection.BuildServiceProvider(); + Assert.Equal(1, serviceProvider.GetRequiredService>().Value.SupportedProtocols.Count); + Assert.Equal(0, serviceProvider.GetRequiredService>>().Value.SupportedProtocols.Count); + } } public class CustomHub : Hub