1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Turn sessions on or off

This commit is contained in:
Blake Mizerany 2007-10-01 21:20:45 -07:00
parent c333cdb8bf
commit 01061464e0
4 changed files with 38 additions and 4 deletions

View file

@ -1,9 +1,13 @@
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib'
require 'sinatra'
# get '/' do
# "Hello World!"
# end
production do
sessions :off
end
get '/' do
"Hello World!"
end
get '/erb.xml' do
header 'Content-Type' => 'application/xml'
@ -18,3 +22,9 @@ get '/erb2' do
erb 'Hello <%= params[:name].capitalize || "World" %> 2!'
end
# Custom 404
get 404 do
'Custom 404!!!!'
end

View file

@ -36,4 +36,7 @@ module Kernel
end
end
def sessions(on_off)
Sinatra::Session::Cookie.use = on_off
end
end

View file

@ -10,7 +10,7 @@ module Sinatra
def start
begin
tail_thread = tail(Options.log_file)
Rack::Handler::Mongrel.run(Rack::Session::Cookie.new(Dispatcher.new), :Port => Options.port) do |server|
Rack::Handler::Mongrel.run(Sinatra::Session::Cookie.new(Dispatcher.new), :Port => Options.port) do |server|
puts "== Sinatra has taken the stage on port #{server.port}!"
trap("INT") do
server.stop

21
lib/sinatra/sessions.rb Normal file
View file

@ -0,0 +1,21 @@
module Sinatra
module Session
class Cookie
def self.use=(v)
@@use = v unless Sinatra::Server.running # keep is thread-safe!
end
def initialize(app, options = {})
@app = if (@@use ||= :on) == :off
app
else
Rack::Session::Cookie.new(app)
end
end
def call(env)
@app.call(env)
end
end
end
end