[英]How to change http.sys web server response when maxconnection limit reached
We are using http sys web server to host web api service.我们正在使用 http sys web 服务器来托管 web Z8A5DA52ED126447D359E70C0572 服务。 Business requires to limit maximum number of concurrent connections.
业务需要限制最大并发连接数。 MaxConnections configuration property used for that purpose:
用于该目的的 MaxConnections 配置属性:
services.Configure<HttpSysOptions>(options =>
{
options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
});
But in case when concurrent connection limit reached all new connections got dropped on a socket level.但是,当并发连接限制达到所有新连接时,所有新连接都会在套接字级别被丢弃。 Is it possible to change this behaviour so server accepts the request and returns 4xx or 5xx response to the client?
是否可以更改此行为,以便服务器接受请求并向客户端返回 4xx 或 5xx 响应?
I have finally managed to find a solution: there is Http503Verbosity property in options.我终于设法找到了解决方案:选项中有Http503Verbosity属性。 By default it is set to Http503VerbosityLevel.Basic but if to change it to Http503VerbosityLevel.Limited or Http503VerbosityLevel.Full 503 response will be returned for requests above limit.
默认情况下,它设置为Http503VerbosityLevel.Basic但如果将其更改为 Http503VerbosityLevel.Limited 或 Http503VerbosityLevel.Full 503 响应将返回超过限制的请求。 So my code looks like this now:
所以我的代码现在看起来像这样:
services.Configure<HttpSysOptions>(options =>
{
options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
options.Http503Verbosity = Http503VerbosityLevel.Full;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.