Coder Social home page Coder Social logo

Comments (2)

jchristn avatar jchristn commented on August 15, 2024

Hello @yashhema there is no capability today in the library to do this. You could however maintain a variable in your application that is incremented each time a connection is being serviced and decremented thereafter, and you could configure the PreRoutingHandler to check this variable and either permit (return false) or deny/terminate the connection (return true).

        /// <summary>
        /// Function to call prior to routing.  
        /// Return 'true' if the connection should be terminated.
        /// Return 'false' to allow the connection to continue routing.
        /// </summary>
        public Func<HttpContext, Task<bool>> PreRoutingHandler = null;

from watsonwebserver.

jchristn avatar jchristn commented on August 15, 2024

Hi @yashhema please try v3.3.0.2 and re-open if any issues.

NuGet: https://www.nuget.org/packages/Watson/3.3.0.2
Commit: 91043a5

Usage:

_Server = new Server("127.0.0.1", 8000, false, DefaultRoute);
_Server.MaxRequests = 5;
_Server.Start();

static async Task DefaultRoute(HttpContext ctx)
{
  // your code here
}

Implementation: if the private _RequestCount exceeds MaxRequests, await _HttpListener.GetContextAsync(); is not entered. Instead the server will pause for 100ms and restart the loop.

Cheers, Joel

from watsonwebserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.