aspnetcore/samples/ResponseCompressionSample/Startup.cs

43 lines
1.3 KiB
C#

// 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 Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
namespace ResponseCompressionSample
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<ICompressionProvider, GzipCompressionProvider>();
services.AddTransient<ICompressionProvider, CustomCompressionProvider>();
services.AddResponseCompression("text/plain", "text/html");
}
public void Configure(IApplicationBuilder app)
{
app.UseResponseCompression();
app.Run(async context =>
{
context.Response.ContentType = "text/plain";
await context.Response.WriteAsync(LoremIpsum.Text);
});
}
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}