Created
March 15, 2012 13:16
-
-
Save npj/2044147 to your computer and use it in GitHub Desktop.
Rack IP Filter + HTTP Basic Auth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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