justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.92k stars 598 forks source link

Limit Sessions Per Client #924

Open korolossamy opened 1 year ago

korolossamy commented 1 year ago

Hi Team,

I would Like to Limit 100 Sessions or Threads per Each Client connect to Proxy server What i have tried on below but still not limited

`
private async Task ProxyServer_BeforeRequest(object sender, SessionEventArgs e) { if (ClientConnectionCount <= 100) {

        SessionListItem item = null;
            await Dispatcher.InvokeAsync(() => { item = addSession(e); });

            if (e.HttpClient.Request.HasBody)
            {
                e.HttpClient.Request.KeepBody = true;
                await e.GetRequestBody();

                if (item == SelectedSession)
                {
                    await Dispatcher.InvokeAsync(selectedSessionChanged);
                }
            }
        }
        else
        {
            var res = new Response();
            res.StatusCode = 400;
            res.StatusDescription = "Limit Exceeded";
            e.Respond(res, true);

        }
    }`