镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

interval.rb allowed? not calling super  #4

Open

Description

@morgz

I may be missing something but it seems strange that

 def allowed?(request)
      t1 = request_start_time(request)
      t0 = cache_get(key = cache_key(request)) rescue nil
      allowed = !t0 || (dt = t1 - t0.to_f) >= minimum_interval
      begin
        cache_set(key, t1)
        allowed
      rescue => e
        # If an error occurred while trying to update the timestamp stored
        # in the cache, we will fall back to allowing the request through.
        # This prevents the Rack application blowing up merely due to a
        # backend cache server (Memcached, Redis, etc.) being offline.
        allowed = true
      end
    end

in interval.rb doesn't call the super implementation in limiter.rb

def allowed?(request)
  case
    when whitelisted?(request) then true
    when blacklisted?(request) then false
    else true # override in subclasses
  end
end

Activity

  1. self-assigned this
    on Nov 14, 2014
  2. GuyPaddock commented on Oct 7, 2016

    @GuyPaddock

    The tricky part here is that you can't really just call super because it handles both the whitelist and blacklist cases. If the user is whitelisted then they shouldn't be subject to any limiting whatsoever, whereas if they're blacklisted, they should always be limited. It's almost like the superclass needs some method you can call that takes a block that is only executed if the user is neither whitelisted nor blacklisted, to avoid the sub-class having to duplicate the superclass logic.

  3. FreekingDean commented on Oct 10, 2016

    @FreekingDean
    Collaborator

    Right, I believe the block implementation would be best, but I am looking into other options that might be more straightforward :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions