Skip to content

Instantly share code, notes, and snippets.

@karmi
Created March 3, 2010 11:37
Show Gist options
  • Save karmi/320549 to your computer and use it in GitHub Desktop.
Save karmi/320549 to your computer and use it in GitHub Desktop.
Using Sinatra with Rack::Auth::Basic and Rack::Cache
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