Skip to content

Instantly share code, notes, and snippets.

@npj
Created March 15, 2012 13:16
Show Gist options
  • Select an option

  • Save npj/2044147 to your computer and use it in GitHub Desktop.

Select an option

Save npj/2044147 to your computer and use it in GitHub Desktop.
Rack IP Filter + HTTP Basic Auth
class FilterAuth < ::Rack::Auth::Basic
def initialize(app, options = { }, realm=nil, &authenticator)
super(app, realm, &authenticator)
@ip_filter = ::Rack::Access.new(app, options)
end
def call(env)
# only need to do auth if the ip filter blocks the request
response = @ip_filter.call(env)
if response[0] == 403
return super(env)
else
return response
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment