Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f89d513

Browse files
committed
Address feedback
1 parent 11696f9 commit f89d513

15 files changed

+39
-39
lines changed

src/Components/WebAssembly/Samples/HostedBlazorWebassemblyApp/Server/appsettings.Development.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"HotReloadStaticAssets": true,
32
"Logging": {
43
"LogLevel": {
54
"Default": "Information",

src/Components/WebAssembly/Server/src/Builder/WebAssemblyRazorComponentsEndpointConventionBuilderExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public static RazorComponentsEndpointConventionBuilder AddInteractiveWebAssembly
5252
ComponentEndpointConventionBuilderHelper.AddRenderMode(builder, new WebAssemblyRenderModeWithOptions(options));
5353

5454
var endpointBuilder = ComponentEndpointConventionBuilderHelper.GetEndpointRouteBuilder(builder);
55-
var environment = endpointBuilder.ServiceProvider.GetRequiredService<IHostEnvironment>();
5655

5756
// If the static assets data source for the given manifest name is already added, then just wire-up the Blazor WebAssembly conventions.
5857
// MapStaticWebAssetEndpoints is idempotent and will not add the data source if it already exists.
@@ -64,7 +63,9 @@ public static RazorComponentsEndpointConventionBuilder AddInteractiveWebAssembly
6463

6564
return builder;
6665
}
67-
else if (environment.IsDevelopment())
66+
67+
var environment = endpointBuilder.ServiceProvider.GetRequiredService<IHostEnvironment>();
68+
if (environment.IsDevelopment())
6869
{
6970
var logger = endpointBuilder.ServiceProvider.GetRequiredService<ILogger<WebAssemblyComponentsEndpointOptions>>();
7071
if (options.StaticAssetsManifestPath is null)

src/Components/WebAssembly/Server/src/ComponentsWebAssemblyStaticAssetsEndpointConventionBuilderExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Routing;
77
using Microsoft.AspNetCore.StaticAssets;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Net.Http.Headers;
910

1011
namespace Microsoft.AspNetCore.Components.WebAssembly.Server;
1112

@@ -62,7 +63,7 @@ private static void WrapEndpoint(EndpointBuilder endpoint)
6263
{
6364
var webHostEnvironment = context.RequestServices.GetRequiredService<IWebHostEnvironment>();
6465
context.Response.Headers.Add("Blazor-Environment", webHostEnvironment.EnvironmentName);
65-
context.Response.Headers.Add("Cache-Control", "no-cache");
66+
context.Response.Headers.Add(HeaderNames.CacheControl, "no-cache");
6667

6768
// DOTNET_MODIFIABLE_ASSEMBLIES is used by the runtime to initialize hot-reload specific environment variables and is configured
6869
// by the launching process (dotnet-watch / Visual Studio).
@@ -83,5 +84,5 @@ private static void WrapEndpoint(EndpointBuilder endpoint)
8384
};
8485
}
8586

86-
private sealed class WebAssemblyConventionsAppliedMetadata { };
87+
private sealed class WebAssemblyConventionsAppliedMetadata;
8788
}

src/Http/Routing/src/Matching/ContentEncodingNegotiationMatcherPolicy.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.AspNetCore.Routing.Matching;
88

9-
internal class ContentEncodingNegotiationMatcherPolicy : NegotiationMatcherPolicy<ContentEncodingMetadata>
9+
internal sealed class ContentEncodingNegotiationMatcherPolicy : NegotiationMatcherPolicy<ContentEncodingMetadata>
1010
{
1111
internal static string HeaderName => "Accept-Encoding";
1212

@@ -28,7 +28,7 @@ private protected override bool IsDefaultMetadataValue(ReadOnlySpan<char> candid
2828

2929
private protected override NegotiationPolicyJumpTable CreateTable(int exitDestination, (string negotiationValue, double quality, int destination)[] destinations, int noNegotiationHeaderDestination) => new ContentEncodingPolicyJumpTable(exitDestination, noNegotiationHeaderDestination, new ContentEncodingDestinationsLookUp(destinations));
3030

31-
internal class ContentEncodingPolicyJumpTable(int anyContentEncodingDestination, int noContentEncodingDestination, ContentEncodingDestinationsLookUp destinations) : NegotiationPolicyJumpTable("Accept-Encoding", anyContentEncodingDestination, noContentEncodingDestination)
31+
internal sealed class ContentEncodingPolicyJumpTable(int anyContentEncodingDestination, int noContentEncodingDestination, ContentEncodingDestinationsLookUp destinations) : NegotiationPolicyJumpTable("Accept-Encoding", anyContentEncodingDestination, noContentEncodingDestination)
3232
{
3333
private readonly ContentEncodingDestinationsLookUp _destinations = destinations;
3434

@@ -37,7 +37,7 @@ internal class ContentEncodingPolicyJumpTable(int anyContentEncodingDestination,
3737
protected override double GetQuality(string? value) => _destinations.GetValueQuality(value);
3838
}
3939

40-
internal class ContentEncodingDestinationsLookUp
40+
internal sealed class ContentEncodingDestinationsLookUp
4141
{
4242
private readonly int _brotliDestination = -1;
4343
private readonly double _brotliQuality;
@@ -76,6 +76,9 @@ public ContentEncodingDestinationsLookUp((string contentEncoding, double quality
7676

7777
public int GetDestination(string? negotiationValue)
7878
{
79+
// Specialcase the lookup based on the length of the negotiation value
80+
// to reduce the number of required comparisons needed to find a match.
81+
// The match will be validated after this selection.
7982
var (matchedEncoding, destination) = negotiationValue?.Length switch
8083
{
8184
2 => ("br", _brotliDestination),

src/Http/Routing/src/Matching/NegotiationMatcherPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ private void EvaluateCandidate(
198198
}
199199

200200
// Explainer:
201-
// This is responsible for building the branches in the DFA that will be used to match the
202-
// based on the Accept-Encoding header of the request.
201+
// This is responsible for building the branches in the DFA that will be used to match a
202+
// concrete endpoint based on the Accept-Encoding header of the request.
203203
// To give you an idea lets explain this through a sample.
204204
// Say we have the following endpoints:
205205
// 1 - Resource.css - [ Accept-Encoding: gzip ]

src/StaticAssets/src/Development/StaticAssetDescriptorExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static long GetContentLength(this StaticAssetDescriptor descriptor)
1313
{
1414
foreach (var header in descriptor.ResponseHeaders)
1515
{
16-
if (header.Name == "Content-Length")
16+
if (string.Equals(header.Name, HeaderNames.ContentLength, StringComparison.OrdinalIgnoreCase))
1717
{
1818
return long.Parse(header.Value, CultureInfo.InvariantCulture);
1919
}
@@ -26,7 +26,7 @@ internal static DateTimeOffset GetLastModified(this StaticAssetDescriptor descri
2626
{
2727
foreach (var header in descriptor.ResponseHeaders)
2828
{
29-
if (header.Name == "Last-Modified")
29+
if (string.Equals(header.Name, HeaderNames.LastModified, StringComparison.OrdinalIgnoreCase))
3030
{
3131
return DateTimeOffset.Parse(header.Value, CultureInfo.InvariantCulture);
3232
}
@@ -39,7 +39,7 @@ internal static EntityTagHeaderValue GetWeakETag(this StaticAssetDescriptor desc
3939
{
4040
foreach (var header in descriptor.ResponseHeaders)
4141
{
42-
if (header.Name == "ETag")
42+
if (string.Equals(header.Name, HeaderNames.ETag, StringComparison.OrdinalIgnoreCase))
4343
{
4444
var eTag = EntityTagHeaderValue.Parse(header.Value);
4545
if (eTag.IsWeak)
@@ -56,7 +56,7 @@ internal static bool HasContentEncoding(this StaticAssetDescriptor descriptor)
5656
{
5757
foreach (var selector in descriptor.Selectors)
5858
{
59-
if (selector.Name == "Content-Encoding")
59+
if (string.Equals(selector.Name, HeaderNames.ContentEncoding, StringComparison.OrdinalIgnoreCase))
6060
{
6161
return true;
6262
}
@@ -69,7 +69,7 @@ internal static bool HasETag(this StaticAssetDescriptor descriptor, string tag)
6969
{
7070
foreach (var header in descriptor.ResponseHeaders)
7171
{
72-
if (header.Name == "ETag")
72+
if (string.Equals(header.Name, HeaderNames.ETag, StringComparison.OrdinalIgnoreCase))
7373
{
7474
var eTag = EntityTagHeaderValue.Parse(header.Value);
7575
if (!eTag.IsWeak && eTag.Tag == tag)

src/StaticAssets/src/Development/StaticAssetDevelopmentRuntimeHandler.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace Microsoft.AspNetCore.Builder;
2525
// Handles changes during development to support common scenarios where for example, a developer changes a file in the wwwroot folder.
2626
internal sealed partial class StaticAssetDevelopmentRuntimeHandler(List<StaticAssetDescriptor> descriptors)
2727
{
28+
internal const string ReloadStaticAssetsAtRuntimeKey = "ReloadStaticAssetsAtRuntime";
29+
2830
public void AttachRuntimePatching(EndpointBuilder builder)
2931
{
3032
var original = builder.RequestDelegate!;
@@ -125,7 +127,7 @@ public Task SendFileAsync(string path, long offset, long? count, CancellationTok
125127
{
126128
// Clear all the ETag headers, as they'll be replaced with the new ones.
127129
_context.Response.Headers.ETag = "";
128-
// Compute the new ETag, if this is a compressed asset, HotReloadStaticAsset will update it.
130+
// Compute the new ETag, if this is a compressed asset, RuntimeStaticAssetResponseBodyFeature will update it.
129131
_context.Response.Headers.ETag = GetETag(fileInfo);
130132
_context.Response.Headers.ContentLength = fileInfo.Length;
131133
_context.Response.Headers.LastModified = fileInfo.LastModified.ToString("ddd, dd MMM yyyy HH:mm:ss 'GMT'", CultureInfo.InvariantCulture);
@@ -157,7 +159,7 @@ private static StaticAssetDescriptor FindOriginalAsset(string tag, List<StaticAs
157159
internal static bool IsEnabled(IServiceProvider serviceProvider, IWebHostEnvironment environment)
158160
{
159161
var config = serviceProvider.GetRequiredService<IConfiguration>();
160-
var explicitlyConfigured = bool.TryParse(config["HotReloadStaticAssets"], out var hotReload);
162+
var explicitlyConfigured = bool.TryParse(config[ReloadStaticAssetsAtRuntimeKey], out var hotReload);
161163
return (!explicitlyConfigured && environment.IsDevelopment()) || (explicitlyConfigured && hotReload);
162164
}
163165

@@ -170,7 +172,7 @@ internal static void EnableSupport(
170172
var config = endpoints.ServiceProvider.GetRequiredService<IConfiguration>();
171173
var hotReloadHandler = new StaticAssetDevelopmentRuntimeHandler(descriptors);
172174
builder.Add(hotReloadHandler.AttachRuntimePatching);
173-
var disableFallback = bool.TryParse(config["DisableStaticAssetFallback"], out var disableFallbackValue) && disableFallbackValue;
175+
var disableFallback = bool.TryParse(config["DisableStaticAssetNotFoundRuntimeFallback"], out var disableFallbackValue) && disableFallbackValue;
174176

175177
if (!disableFallback)
176178
{

src/StaticAssets/src/EndpointProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.AspNetCore.StaticAssets;
77

88
// Represents a property of an endpoint.
99
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
10-
internal class EndpointProperty(string name, string value)
10+
internal sealed class EndpointProperty(string name, string value)
1111
{
1212
public string Name { get; } = name;
1313
public string Value { get; } = value;

src/StaticAssets/src/Infrastructure/StaticAssetsEndpointDataSourceHelper.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
namespace Microsoft.AspNetCore.StaticAssets.Infrastructure;
99

1010
/// <summary>
11-
/// This type is not recommended for use outside of ASP.NET Core.
11+
/// For internal framework use only.
1212
/// </summary>
1313
public static class StaticAssetsEndpointDataSourceHelper
1414
{
1515
/// <summary>
16-
/// This method is not recommended for use outside of ASP.NET Core.
16+
/// For internal framework use only.
1717
/// </summary>
18-
/// <param name="dataSource"></param>
19-
/// <param name="staticAssetsManifestPath"></param>
20-
2118
public static bool IsStaticAssetsDataSource(EndpointDataSource dataSource, string? staticAssetsManifestPath = null)
2219
{
2320
if (dataSource is StaticAssetsEndpointDataSource staticAssetsDataSource)

src/StaticAssets/src/ResponseHeader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace Microsoft.AspNetCore.StaticAssets;
77

88
// Represents a response header for a static resource.
99
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
10-
internal class ResponseHeader(string name, string value)
10+
internal sealed class ResponseHeader(string name, string value)
1111
{
1212
public string Name { get; } = name;
1313
public string Value { get; } = value;
1414

15-
private string GetDebuggerDisplay() => $"Name: {Name} Value:{Value}";
15+
private string GetDebuggerDisplay() => $"Name: {Name} Value: {Value}";
1616
}

0 commit comments

Comments
 (0)