Class: Gloo::WebSvr::Session
- Inherits:
-
Object
- Object
- Gloo::WebSvr::Session
- Defined in:
- lib/gloo/web_svr/session.rb
Constant Summary collapse
- SESSION_CONTAINER =
'session'.freeze
Instance Method Summary collapse
-
#add_session_for_response(headers) ⇒ Object
If there is session data, encrypt and add it to the response.
-
#cookie_expires ⇒ Object
Get the expiration time for the session cookie.
-
#cookie_path ⇒ Object
Get the path for the session cookie.
-
#decode_decrypt(data) ⇒ Object
Decode and decrypt the session data.
-
#encrypt_encode(data) ⇒ Object
Encrypt and encode the session data.
-
#initialize(engine, server_obj) ⇒ Session
constructor
Set up the web server.
-
#iv ⇒ Object
Get the initialization vector for the cipher.
-
#key ⇒ Object
Get the key for the encryption cipher.
-
#secure_cookie? ⇒ Boolean
Should the session cookie be secure?.
-
#session_name ⇒ Object
Get the session cookie name.
-
#set_session_data_for_request(env) ⇒ Object
Get the session data from the encrypted cookie.
Constructor Details
#initialize(engine, server_obj) ⇒ Session
Set up the web server.
27 28 29 30 31 32 |
# File 'lib/gloo/web_svr/session.rb', line 27 def initialize( engine, server_obj ) @engine = engine @log = @engine.log @server_obj = server_obj end |
Instance Method Details
#add_session_for_response(headers) ⇒ Object
If there is session data, encrypt and add it to the response. Once done, clear out the session data.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/gloo/web_svr/session.rb', line 70 def add_session_for_response( headers ) # Are we using sessions? if @server_obj.use_session? # Build and add encrypted session data data = @server_obj.get_session_data unless data.empty? data = encrypt_encode( data ) session_hash = { value: data, path: , expires: , http_only: true } if session_hash[ :secure ] = true end Rack::Utils.( headers, session_name, session_hash ) end # Clear out session data @server_obj.clear_session_data end return headers end |
#cookie_expires ⇒ Object
Get the expiration time for the session cookie.
148 149 150 |
# File 'lib/gloo/web_svr/session.rb', line 148 def return @server_obj. end |
#cookie_path ⇒ Object
Get the path for the session cookie.
141 142 143 |
# File 'lib/gloo/web_svr/session.rb', line 141 def return @server_obj. end |
#decode_decrypt(data) ⇒ Object
Decode and decrypt the session data.
112 113 114 115 |
# File 'lib/gloo/web_svr/session.rb', line 112 def decode_decrypt( data ) data = Gloo::Objs::Cipher.decrypt( data, key, iv ) return JSON.parse( data ) end |
#encrypt_encode(data) ⇒ Object
Encrypt and encode the session data.
105 106 107 |
# File 'lib/gloo/web_svr/session.rb', line 105 def encrypt_encode( data ) return Gloo::Objs::Cipher.encrypt( data.to_json, key, iv ) end |
#iv ⇒ Object
Get the initialization vector for the cipher.
134 135 136 |
# File 'lib/gloo/web_svr/session.rb', line 134 def iv return @server_obj.encryption_iv end |
#key ⇒ Object
Get the key for the encryption cipher.
127 128 129 |
# File 'lib/gloo/web_svr/session.rb', line 127 def key return @server_obj.encryption_key end |
#secure_cookie? ⇒ Boolean
Should the session cookie be secure?
155 156 157 |
# File 'lib/gloo/web_svr/session.rb', line 155 def return @server_obj. end |
#session_name ⇒ Object
Get the session cookie name.
120 121 122 |
# File 'lib/gloo/web_svr/session.rb', line 120 def session_name return @server_obj.session_name end |
#set_session_data_for_request(env) ⇒ Object
Get the session data from the encrypted cookie. Add it to the session container.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gloo/web_svr/session.rb', line 43 def set_session_data_for_request( env ) = Rack::Utils.( env ) # Are we using sessions? if @server_obj.use_session? data = [ session_name ] if data data = decode_decrypt( data ) data.each do |key, value| @server_obj.set_session_var( key, value ) end end end end |