Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you create dynamic URL (parameter) rules? #29

Closed
kspearrin opened this issue Sep 28, 2017 · 8 comments
Closed

How do you create dynamic URL (parameter) rules? #29

kspearrin opened this issue Sep 28, 2017 · 8 comments
Labels

Comments

@kspearrin
Copy link

kspearrin commented Sep 28, 2017

How do you create dynamic URL rules? For example, I have a URL:

POST example.com/user/{id}/something

where {id} changes per user. I'd like to limit it to 1 call per second per user id.

Should the rule look like this or what?

  {
    "Endpoint": "post:/user/*/something",
    "Period": "1s",
    "Limit": 1
  }

I couldn't find anything in the docs. Thanks!

@stefanprodan
Copy link
Owner

Yes that should work I think, the latest version has a wildcard implementation #25

@STRATZ-Ken
Copy link

Not sure this answers the question. I think what he is asking for the specifics of an Id param. Like his example. Or are you saying to do that, * is the same thing as {id}. I am testing this on latest version and also cannot get a param to be recognized.

@oatsoda
Copy link

oatsoda commented Feb 28, 2018

Is there a way to use the wildcard as part of the rate limit rule? So in the above example what if you want to rate limit any calls to example.com/user/* no matter the Id that was actually used?

@oatsoda
Copy link

oatsoda commented Mar 12, 2018

I think I am asking for the same as #13 which is the inverse of what @kspearrin is asking for.

@acaravia
Copy link

acaravia commented Aug 7, 2018

Did this ever get implemented? Because I've recently implemented this and doesn't appear to work.

@acaravia
Copy link

acaravia commented Aug 7, 2018

Ok I found out the issue. I had several. First I'm just using ClientRateLimiting but looks like it would apply to IPRateLimiting as well.

  1. EndpointWhitelist and ClientWhitelist must contain at least 1 value. I put "none" for my purposes.
  2. endpoints in your config file are case sensitive. The code sets the incoming path ToLowerInvariant but doesn't do the same for config values.
  3. ClientLimiting matching is not using the WildcardMatcher.IsMatch function and IPRateLimiting was just applying it to one check. I downloaded the code and made changes so that all checks used the previously mentioned function and everything appears to be working.

My scenario had an Endpoint: "post:/api/clients//dosomething/". It was able to match on that when calling /api/clients/v1/dosomehting/100. Hope this helps someone out as I just spent the last several hours pulling what little hair I have left out. :)

@VicThorX
Copy link

Hi!
I create this PR based in @acaravia information: Add Custom Middleware to catch EndpointWhiteList

I hope this is useful for someone!

cristipufu added a commit that referenced this issue Feb 16, 2019
cristipufu added a commit that referenced this issue Feb 17, 2019
@cristipufu
Copy link
Collaborator

Check this out: #63

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants