/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Servers/testassets/ServerComparison.TestSites/StartupResponseCompression.cs
61 строка
2 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace ServerComparison.TestSites; public class StartupResponseCompression { public void ConfigureServices(IServiceCollection services) { services.AddResponseCompression(); } public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { // NGinx's default min size is 20 bytes var helloWorldBody = "Hello World;" + new string('a', 20); app.Map("/NoAppCompression", subApp => { subApp.Run(context => { context.Response.ContentType = "text/plain"; context.Response.ContentLength = helloWorldBody.Length; return context.Response.WriteAsync(helloWorldBody); }); }); app.Map("/AppCompression", subApp => { subApp.UseResponseCompression(); subApp.Run(context => { context.Response.ContentType = "text/plain"; context.Response.ContentLength = helloWorldBody.Length; return context.Response.WriteAsync(helloWorldBody); }); }); app.Run(context => { context.Response.ContentType = "text/plain"; string body; if (context.Request.Path.Value == "/") { body = "Running"; } else { body = "Not Implemented: " + context.Request.Path; } context.Response.ContentLength = body.Length; return context.Response.WriteAsync(body); }); } }