Created
March 3, 2010 11:37
-
-
Save karmi/320549 to your computer and use it in GitHub Desktop.
Using Sinatra with Rack::Auth::Basic and Rack::Cache
This file contains 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
require 'rubygems' | |
require 'sinatra/base' | |
require 'rack/cache' | |
gem 'sinatra', '~> 1' # Require Sinatra version 1.x | |
class Application < Sinatra::Base | |
use Rack::Auth::Basic do |username, password| | |
[username, password] == ['admin', 'admin'] | |
end | |
use Rack::Cache, | |
:verbose => true, | |
:metastore => "heap:/", | |
:entitystore => "heap:/" | |
after do | |
# http://www.mnot.net/cache_docs/#CACHE-CONTROL | |
expires 60, :public, :'no-cache', :must_revalidate # Expire in 1 minute, require Auth | |
end | |
get '/' do | |
puts "!!! APP HIT !!!" | |
"Welcome!" | |
end | |
end | |
Application.run! if __FILE__ == $0 | |
# Try with: | |
# $ curl -i http://localhost:4567 | |
# $ curl -i http://admin:admin@localhost:4567 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment