Skip to content

Instantly share code, notes, and snippets.

@jferris
Created February 11, 2010 22:20
Show Gist options
  • Select an option

  • Save jferris/302035 to your computer and use it in GitHub Desktop.

Select an option

Save jferris/302035 to your computer and use it in GitHub Desktop.
class PathBasedAuth
def initialize(app, opts, &block)
@app = app
@path = opts[:path]
@block = block
@auth = Rack::Auth::Basic.new(app, &block)
end
def call(env)
if path_matches?(env)
@auth.call(env)
else
@app.call(env)
end
end
private
def path_matches?(env)
env['REQUEST_URI'] =~ @path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment