简体   繁体   中英

How to change http.sys web server response when maxconnection limit reached

We are using http sys web server to host web api service. Business requires to limit maximum number of concurrent connections. MaxConnections configuration property used for that purpose:

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?

I have finally managed to find a solution: there is Http503Verbosity property in options. 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. So my code looks like this now:

        services.Configure<HttpSysOptions>(options =>
        {
            options.MaxConnections = Configuration.GetValue<long?>("MaxConnections");
            options.Http503Verbosity = Http503VerbosityLevel.Full;
        });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM