Class: Radio::HTTP::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/radio/http/session.rb

Constant Summary collapse

CODES =
('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
'ham21-radio-session'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



38
39
# File 'lib/radio/http/session.rb', line 38

def initialize
end

Class Method Details

.prepare(request, response) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/radio/http/session.rb', line 26

def self.prepare request, response
  @sessions ||= {}
  session_id = request.cookies[COOKIE_KEY]
  session = @sessions[session_id]
  unless session
    session_id = (0...24).collect{CODES.sample}.join
    session = @sessions[session_id] = new
    Rack::Utils.set_cookie_header!(response.headers, COOKIE_KEY, session_id)
  end
  session
end