Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Connections;

namespace Microsoft.AspNetCore.Components.Server;

Expand Down Expand Up @@ -53,4 +54,13 @@ public class ServerComponentsEndpointOptions
/// defined in <see cref="ContentSecurityFrameAncestorsPolicy"/> will be applied.
/// </remarks>
public Func<HttpContext, WebSocketAcceptContext, Task>? ConfigureWebSocketAcceptContext { get; set; }

/// <summary>
/// Gets or sets a callback to configure the <see cref="HttpConnectionDispatcherOptions"/> used by the SignalR connection.
/// </summary>
/// <remarks>
/// This allows configuring options such as <see cref="HttpConnectionDispatcherOptions.CloseOnAuthenticationExpiration"/>,
/// transport options, authorization data, and other connection-level settings.
/// </remarks>
public Action<HttpConnectionDispatcherOptions>? ConfigureConnection { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public override IEnumerable<RouteEndpointBuilder> GetEndpointBuilders(
}

var endpointRouteBuilder = new EndpointRouteBuilder(Services, applicationBuilder);
var hub = endpointRouteBuilder.MapBlazorHub("/_blazor");
var serverRenderMode = (InternalServerRenderMode)renderMode;
var hub = serverRenderMode.Options?.ConfigureConnection is not null
? endpointRouteBuilder.MapBlazorHub("/_blazor", serverRenderMode.Options.ConfigureConnection)
: endpointRouteBuilder.MapBlazorHub("/_blazor");

if (renderMode is InternalServerRenderMode { Options.ConfigureWebSocketAcceptContext: var configureConnection, Options.DisableWebSocketCompression: var disableCompression } &&
(configureConnection is not null || !disableCompression))
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Server/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#nullable enable
Microsoft.AspNetCore.Components.Server.ServerComponentsEndpointOptions.ConfigureConnection.get -> System.Action<Microsoft.AspNetCore.Http.Connections.HttpConnectionDispatcherOptions!>?
Microsoft.AspNetCore.Components.Server.ServerComponentsEndpointOptions.ConfigureConnection.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Connections;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
Expand Down Expand Up @@ -122,6 +123,30 @@ public void MapBlazorHub_AppliesFinalConventionsInFIFOOrder()
Assert.Equal(new[] { "first-in", "last-in" }, populatedMetadata);
}

[Fact]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot get rid of this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the test in commit f5456ce.

public void ServerComponentsEndpointOptions_ConfigureConnection_CanBeSet()
{
// Arrange
var options = new ServerComponentsEndpointOptions();
var configureConnectionCalled = false;

// Act
options.ConfigureConnection = dispatcherOptions =>
{
configureConnectionCalled = true;
dispatcherOptions.CloseOnAuthenticationExpiration = true;
};

// Simulate calling the configuration
var dispatcherOptions = new HttpConnectionDispatcherOptions();
options.ConfigureConnection?.Invoke(dispatcherOptions);

// Assert
Assert.NotNull(options.ConfigureConnection);
Assert.True(configureConnectionCalled);
Assert.True(dispatcherOptions.CloseOnAuthenticationExpiration);
}
Comment thread
javiercn marked this conversation as resolved.
Outdated

private IApplicationBuilder CreateAppBuilder()
{
var environment = new Mock<IWebHostEnvironment>();
Expand Down
Loading