Skip to content

Commit

Permalink
feat: expose Kestrel options in appsettings.json (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 authored Nov 6, 2023
1 parent eb00026 commit dfb6142
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/pages/config/appsettings.zh.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ import { Callout } from "nextra-theme-docs";
// use the following options to allow proxy
"TrustedNetworks": ["10.0.0.0/8"],
"TrustedProxies": ["10.0.0.1"]
},
"Kestrel": {
"Limits": {
"MaxResponseBufferSize": 2048,
"MaxRequestBufferSize": 1048576,
"MaxRequestLineSize": 8192,
"MaxRequestHeadersTotalSize": 32768,
"MaxRequestHeaderCount": 100,
"MaxRequestBodySize": 27262946,
"KeepAliveTimeout": "0.0:5:0",
"RequestHeadersTimeout": "0.0:5:0",
"MaxConcurrentConnections": null,
"MaxConcurrentUpgradedConnections": null
},
"AddServerHeader": true,
"AllowResponseHeaderCompression": true,
"AllowSynchronousIO": false,
"AllowAlternateSchemes": false,
"DisableStringReuse": false,
"ConfigurationLoader": null
}
}
```
Expand Down Expand Up @@ -220,3 +240,9 @@ GZCTF 仅支持 PostgreSQL 作为数据库,不支持 MySQL 等其他数据库
</Callout>

其他字段请参考官方文档描述:[配置 ASP.NET Core 以使用代理服务器和负载均衡器](https://learn.microsoft.com/zh-cn/aspnet/core/host-and-deploy/proxy-load-balancer?view=aspnetcore-7.0)[ForwardedHeadersOptions 类](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.aspnetcore.builder.forwardedheadersoptions?view=aspnetcore-7.0)

### Kestrel

Kestrel 为 GZCTF 自带并使用的 Web 服务器。利用此配置可以自行控制 Kestrel 的行为,例如指定 HTTP 协议、修改请求大小上限等等。

具体可配置字段请参照官方文档中 `KestrelServerOptions` 类的属性: [KestrelServerOptions 类](https://learn.microsoft.com/zh-cn/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserveroptions?view=aspnetcore-7.0)
7 changes: 7 additions & 0 deletions src/GZCTF/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.WebHost.ConfigureKestrel(options =>
{
var kestrelSection = builder.Configuration.GetSection("Kestrel");
options.Configure(kestrelSection);
kestrelSection.Bind(options);
});

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

GZCTF.Program.Banner();
Expand Down

0 comments on commit dfb6142

Please sign in to comment.