require 'rubygems' require 'sinatra' set :port, 3001 helpers do def protected! unless authorized? response['WWW-Authenticate'] = %(Basic realm="BigBench TestWebServer") throw(:halt, [401, "Not authorized\n"]) end end def authorized? @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && @auth.basic? && @auth.credentials && @auth.credentials == ['admin', 'secret'] end end # Base HTTP Verbs get "/" do "Test" end put "/" do "Test" end post "/" do "Test" end delete "/" do "Test" end # Basic Auth URL get "/basic/auth" do protected! "Test" end # Needs Body Params post "/post/content" do status 406 unless params[:name] == "bigbench" and params[:id] == "1" "Test" end