Giter VIP home page Giter VIP logo

Comments (4)

scale-tone avatar scale-tone commented on June 12, 2024

Hi @almightydegu , an IdentityId is a no-op without an IdentityIdExtractor (sorry if it is not clear from the documentation). That might be the reason of what you're observing.

Can you show your IdentityIdExtractor's code?

from throttlingtroll.

almightydegu avatar almightydegu commented on June 12, 2024

Thank you for the reply @scale-tone.

Below is the full object I'm using:

app.UseThrottlingTroll(options =>
{
    options.IdentityIdExtractor = request =>
    {
        return ((IIncomingHttpRequestProxy)request).Request.RouteValues["testId"]?.ToString();
    };

    options.Config = new ThrottlingTrollConfig
    {
        Rules = new[]
        {
            new ThrottlingTrollRule
            {
                UriPattern = "test$",
                IdentityId = "f411b023-dfb0-4756-9319-7bc24d11a682",
                LimitMethod = new FixedWindowRateLimitMethod
                {
                    IntervalInSeconds = 1000,
                    PermitLimit = 10
                }
            },
            new ThrottlingTrollRule
            {
                UriPattern = "test$",
                IdentityId = "758a3ff4-0655-4183-9406-20fbc8cb1bcc",
                LimitMethod = new FixedWindowRateLimitMethod
                {
                    IntervalInSeconds = 1000,
                    PermitLimit = 30
                }
            },
            new ThrottlingTrollRule
            {
                UriPattern = "test$",        
                LimitMethod = new FixedWindowRateLimitMethod
                {
                    IntervalInSeconds = 1000,
                    PermitLimit = 1
                }
            }
        }
    };
});

If I remove the third rule and just use the two rules that have the IdentityId set, then it works as expected, but I want to have a default option to the set up I want

from throttlingtroll.

scale-tone avatar scale-tone commented on June 12, 2024

Then I suggest you return some my-default-identity-id constant from your IdentityIdExtractor, when a request falls into this "default" category. And then have a separate ThrottlingTrollRule with IdentityId="my-default-identity-id".
That will not only work, but will also look explicit - leaves no doubt about how your system behaves.

Also remember, that ThrottlingTrollRule.IdentityId field is optional - when this value is omitted and IdentityIdExtractor is present, then all individual identities will get their separate counters automatically.

from throttlingtroll.

almightydegu avatar almightydegu commented on June 12, 2024

Doing that would mean all other requests would not be treated independently, which is what I was hoping for. I will need to create a rule for each of the IDs as a workaround. I mainly wanted this as a catch-all is a new ID is passed in without a rule and make the rules config cleaner to work with, but I can work around it

from throttlingtroll.

Related Issues (18)

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.