Class: Cassiopeia::RackRestoreRequest
Constant Summary
Constants inherited
from BaseRack
BaseRack::CAS_QUERY_STRING_KEY, BaseRack::CAS_RACK_SESSION_KEY, BaseRack::CAS_RACK_SESSION_STORE, BaseRack::CAS_REQUEST_URI_KEY, BaseRack::CAS_REQ_EXPIRES_AT_KEY, BaseRack::CAS_REQ_REMOVE_RETURN, BaseRack::CAS_REQ_TIMEOUT, BaseRack::CAS_SAVE_KEYS, BaseRack::CAS_TICKET_ID_KEY, BaseRack::CAS_TICKET_KEY, BaseRack::CAS_UNIQUE_REQ_KEY
Instance Method Summary
collapse
Methods inherited from BaseRack
#cas_current_ticket, #cas_current_ticket_valid?, #enabled, #generate_expiration, #generate_req_key, #initialize, #raise_missconfiguration, #response, #restore_headers_required?, #session, #store_headers_required?
Instance Method Details
#add_ticket_id_to_req(env, key, value) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/cassiopeia/rack_restore_request.rb', line 75
def add_ticket_id_to_req(env, key, value)
newparams = query_to_hash(value)
params = query_to_hash(env[key])
newparams[CAS_TICKET_ID_KEY] = params[CAS_TICKET_ID_KEY]
newparams.delete CAS_UNIQUE_REQ_KEY
env[key] = hash_to_query(newparams)
end
|
#call(env) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/cassiopeia/rack_restore_request.rb', line 3
def call( env )
if enabled
if (env)
env = restore_old_request(env)
elsif (env)
remove_expired_requests
store_current_request(env)
end
end
response(env)
end
|
#remove_expired_requests ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/cassiopeia/rack_restore_request.rb', line 54
def remove_expired_requests
begin
CassiopeiaRequest.delete_all(["expires_at <= ?", Time.now.utc])
rescue Exception => e
raise_missconfiguration(e)
end
end
|
#restore_old_request(env) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/cassiopeia/rack_restore_request.rb', line 32
def restore_old_request(env)
begin
key = restore_req_key(env)
request = CassiopeiaRequest.find_by_uid(key)
if request
stored_keys = Marshal.load(request.data)
stored_keys.each do |key,value|
if(key.match(CAS_QUERY_STRING_KEY))
add_ticket_id_to_req(env,key,value)
else
env[key] = value
end
end
end
request.delete if CAS_REQ_REMOVE_RETURN
rescue Exception => e
raise_missconfiguration(e)
end
env
end
|
#restore_req_key(env) ⇒ Object
#store_current_request(env) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cassiopeia/rack_restore_request.rb', line 15
def store_current_request(env)
begin
request = CassiopeiaRequest.new({:uid => store_req_key(env), :expires_at => generate_expiration})
store = {}
env.each do |key,value|
if env[key] && (key.is_a? String) && (key.match("HTTP_") || CAS_SAVE_KEYS.match(key))
store[key] = value
end
end
request.data = Marshal.dump(store)
request.save!
rescue Exception => e
raise_missconfiguration(e)
end
end
|
#store_req_key(env) ⇒ Object