[Blazor] Remove compression middleware from the template (#19285)

Remove response compression from the template
This commit is contained in:
Javier Calvarro Nelson 2020-02-24 11:03:00 -08:00 committed by GitHub
parent 9c16db3e89
commit 226f461806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 12 deletions

View File

@ -36,7 +36,7 @@ namespace Microsoft.AspNetCore.Builder
/// <param name="builder">The <see cref="IApplicationBuilder"/>.</param> /// <param name="builder">The <see cref="IApplicationBuilder"/>.</param>
/// <param name="pathPrefix">The <see cref="PathString"/> that indicates the prefix for the Blazor WebAssembly application.</param> /// <param name="pathPrefix">The <see cref="PathString"/> that indicates the prefix for the Blazor WebAssembly application.</param>
/// <returns>The <see cref="IApplicationBuilder"/></returns> /// <returns>The <see cref="IApplicationBuilder"/></returns>
public static IApplicationBuilder MapBlazorFrameworkFiles(this IApplicationBuilder builder, PathString pathPrefix) public static IApplicationBuilder UseBlazorFrameworkFiles(this IApplicationBuilder builder, PathString pathPrefix)
{ {
if (builder is null) if (builder is null)
{ {
@ -53,8 +53,6 @@ namespace Microsoft.AspNetCore.Builder
{ {
subBuilder.Use(async (ctx, next) => subBuilder.Use(async (ctx, next) =>
{ {
// At this point we mapped something from the /_framework
ctx.Response.Headers.Append(HeaderNames.CacheControl, "no-cache");
// This will invoke the static files middleware plugged-in below. // This will invoke the static files middleware plugged-in below.
NegotiateEncoding(ctx, webHostEnvironment); NegotiateEncoding(ctx, webHostEnvironment);
await next(); await next();
@ -73,7 +71,7 @@ namespace Microsoft.AspNetCore.Builder
/// <param name="pathPrefix">The <see cref="PathString"/> that indicates the prefix for the Blazor WebAssembly application.</param> /// <param name="pathPrefix">The <see cref="PathString"/> that indicates the prefix for the Blazor WebAssembly application.</param>
/// <returns>The <see cref="IApplicationBuilder"/></returns> /// <returns>The <see cref="IApplicationBuilder"/></returns>
public static IApplicationBuilder UseBlazorFrameworkFiles(this IApplicationBuilder applicationBuilder) => public static IApplicationBuilder UseBlazorFrameworkFiles(this IApplicationBuilder applicationBuilder) =>
MapBlazorFrameworkFiles(applicationBuilder, default); UseBlazorFrameworkFiles(applicationBuilder, default);
private static StaticFileOptions CreateStaticFilesOptions(IFileProvider webRootFileProvider) private static StaticFileOptions CreateStaticFilesOptions(IFileProvider webRootFileProvider)
{ {
@ -92,6 +90,9 @@ namespace Microsoft.AspNetCore.Builder
// sending the file. // sending the file.
options.OnPrepareResponse = fileContext => options.OnPrepareResponse = fileContext =>
{ {
// At this point we mapped something from the /_framework
fileContext.Context.Response.Headers.Append(HeaderNames.CacheControl, "no-cache");
var requestPath = fileContext.Context.Request.Path; var requestPath = fileContext.Context.Request.Path;
if (string.Equals(Path.GetExtension(requestPath.Value), ".gz")) if (string.Equals(Path.GetExtension(requestPath.Value), ".gz"))
{ {

View File

@ -76,19 +76,11 @@ namespace ComponentsWebAssembly_CSharp.Server
#if (IndividualLocalAuth) #if (IndividualLocalAuth)
services.AddRazorPages(); services.AddRazorPages();
#endif #endif
services.AddResponseCompression(opts =>
{
opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/octet-stream" });
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{ {
app.UseResponseCompression();
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();