Use minimal APIs for Response Compression endpoints (#25408)

* Use minimal APIS for Response Compression endpoints

* .
pull/25406/head
Kirk Larkin 2022-03-24 17:38:22 +00:00 committed by GitHub
parent d1cceeab13
commit 198fdcdc04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 32 additions and 66 deletions

View File

@ -77,50 +77,33 @@ using ResponseCompressionSample;
var builder = WebApplication.CreateBuilder(args);
//builder.Services.AddResponseCompression();
// builder.Services.AddResponseCompression();
var app = builder.Build();
//app.UseResponseCompression();
// app.UseResponseCompression();
app.Map("/trickle", trickleApp =>
app.Map("/trickle", async (HttpResponse httpResponse) =>
{
trickleApp.Run(async context =>
httpResponse.ContentType = "text/plain;charset=utf-8";
for (int i = 0; i < 20; i++)
{
context.Response.ContentType = "text/plain";
for (int i = 0; i < 20; i++)
{
await context.Response.WriteAsync("a");
await context.Response.Body.FlushAsync();
await Task.Delay(TimeSpan.FromMilliseconds(50));
}
});
await httpResponse.WriteAsync("a");
await httpResponse.Body.FlushAsync();
await Task.Delay(TimeSpan.FromMilliseconds(50));
}
});
app.Map("/testfile1kb.txt", fileApp =>
{
fileApp.Run(context =>
{
context.Response.ContentType = "text/plain";
return context.Response.SendFileAsync("testfile1kb.txt");
});
});
app.Map("/testfile1kb.txt", () => Results.File(
app.Environment.ContentRootFileProvider.GetFileInfo("testfile1kb.txt").PhysicalPath,
"text/plain;charset=utf-8"));
app.Map("/banner.svg", fileApp =>
{
fileApp.Run(context =>
{
context.Response.ContentType = "image/svg+xml";
return context.Response.SendFileAsync("banner.svg");
});
});
app.Map("/banner.svg", () => Results.File(
app.Environment.ContentRootFileProvider.GetFileInfo("banner.svg").PhysicalPath,
"image/svg+xml;charset=utf-8"));
app.Run(async context =>
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(LoremIpsum.Text);
});
app.MapFallback(() => LoremIpsum.Text);
app.Run();
#endregion
@ -148,44 +131,27 @@ var app = builder.Build();
app.UseResponseCompression();
#endregion
app.Map("/trickle", trickleApp =>
app.Map("/trickle", async (HttpResponse httpResponse) =>
{
trickleApp.Run(async context =>
httpResponse.ContentType = "text/plain;charset=utf-8";
for (int i = 0; i < 20; i++)
{
context.Response.ContentType = "text/plain";
for (int i = 0; i < 20; i++)
{
await context.Response.WriteAsync("a");
await context.Response.Body.FlushAsync();
await Task.Delay(TimeSpan.FromMilliseconds(25));
}
});
await httpResponse.WriteAsync("a");
await httpResponse.Body.FlushAsync();
await Task.Delay(TimeSpan.FromMilliseconds(50));
}
});
app.Map("/testfile1kb.txt", fileApp =>
{
fileApp.Run(context =>
{
context.Response.ContentType = "text/plain";
return context.Response.SendFileAsync("testfile1kb.txt");
});
});
app.Map("/testfile1kb.txt", () => Results.File(
app.Environment.ContentRootFileProvider.GetFileInfo("testfile1kb.txt").PhysicalPath,
"text/plain;charset=utf-8"));
app.Map("/banner.svg", fileApp =>
{
fileApp.Run(context =>
{
context.Response.ContentType = "image/svg+xml";
return context.Response.SendFileAsync("banner.svg");
});
});
app.Map("/banner.svg", () => Results.File(
app.Environment.ContentRootFileProvider.GetFileInfo("banner.svg").PhysicalPath,
"image/svg+xml;charset=utf-8"));
app.Run(async context =>
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(LoremIpsum.Text);
});
app.MapFallback(() => LoremIpsum.Text);
app.Run();
#endregion