big_session 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 994588f4941c7cc708c7eb25b6c83eeccd3152955e3383dd9091d5760e80c564
4
- data.tar.gz: 89b653bd49cf3d7cb121edef8fdd7b4a813f95fa3533f1499c0140890dbfce33
3
+ metadata.gz: 5df74f239e196ec09817590c3618f7e5689c48e273e33b284f836fefd3f69318
4
+ data.tar.gz: 2d0b08359ab3d997e84900b6b7a960fefb3f8bedfba39de928c5b13d974cccc4
5
5
  SHA512:
6
- metadata.gz: e861d9b437bb3ed1080ad04fdff2e58a5df8031a97a9d643efd1dd6ccd6fb2fc4759db98cfe8dedb21f33c397b6f97a48efaaeb418b554a7154be1f9cc8c14b0
7
- data.tar.gz: bdd49cd22dd15c31a305423020abfd1663057e141fcfb8de76849756c909f8be7b27a3766b112bcf35f39ad69c75514ac831af94a4bcb4cbfe9c36c27eb2f414
6
+ metadata.gz: c4719aaa0e5404daa58fa3cf38be0d08ab92a1841ef2700e71480f4164d249bff464ce69a3e059a8bcce3e003b141e5827d01f8e86f245d8f1d26a364aa5b732
7
+ data.tar.gz: 771b9f7a1959a62a6610e07032d92cbd3a5ae8b87cf02d1bbcbd7af21c480047ce31069f46895afe31ee07798710e02b1237d9ad35ff303db7a033f33086f478
@@ -10,6 +10,6 @@ module BigSession
10
10
 
11
11
  BIG_SESSION_HEADER_NAME = 'X-Bigse-SessionID'
12
12
  BIG_SESSION_SIGNATURE_HEADER_NAME = 'X-Bigse-Sig'
13
- THREAD_BIG_SESSION_ID_KEY = 'big_session_id'
13
+ THREAD_BIG_SESSION_CONTAINER_KEY = 'big_session_id'
14
14
  RAILS_SESSION_BIG_SESSION_ID_KEY = 'big_session_id'
15
15
  end
@@ -20,32 +20,33 @@ module BigSession
20
20
  end
21
21
 
22
22
  def call(env)
23
+ session_id = retrieve_or_generate_session_id(env)
24
+ env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY] = session_id
25
+ SessionId.with_session_id(session_id) do
26
+ @app.call(env)
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def retrieve_or_generate_session_id(env)
23
33
  header_session_id, header_signature = env.values_at(
24
34
  'HTTP_' + ::BigSession::BIG_SESSION_HEADER_NAME.upcase.gsub(/-/, '_'),
25
35
  'HTTP_' + ::BigSession::BIG_SESSION_SIGNATURE_HEADER_NAME
26
36
  .upcase.gsub(/-/, '_')
27
37
  )
28
38
 
29
- if header_session_id
30
- env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY] =
31
- if @header_secret
32
- validate_header_session_id(header_session_id, header_signature)
33
- else
34
- header_session_id
35
- end
36
-
37
- SessionId.set(env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY])
38
- else
39
- SessionId.set(env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY]) unless SessionId.current
40
- env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY] = SessionId.current
41
- end
39
+ return validate_header_session_id(header_session_id, header_signature) \
40
+ if header_session_id
42
41
 
43
- @app.call(env)
42
+ SessionId.current ||
43
+ env['rack.session'][::BigSession::RAILS_SESSION_BIG_SESSION_ID_KEY] ||
44
+ SessionId.new_session_id
44
45
  end
45
46
 
46
- private
47
-
48
47
  def validate_header_session_id(header_session_id, header_signature)
48
+ return header_session_id unless @header_secret
49
+
49
50
  digest = OpenSSL::HMAC.hexdigest('sha256', @header_secret, header_session_id)
50
51
  return header_session_id if digest == header_signature
51
52
 
@@ -6,20 +6,33 @@ module BigSession
6
6
  # SessionId object bridges an access from users to session id
7
7
  class SessionId
8
8
  class << self
9
+ def with_session_id(session_id, &_block)
10
+ container.push(session_id)
11
+ yield
12
+ ensure
13
+ container.pop
14
+ end
15
+
9
16
  def current
10
- Thread.current[::BigSession::THREAD_BIG_SESSION_ID_KEY]
17
+ container.last
11
18
  end
12
19
 
20
+ =begin
13
21
  def set(value = nil)
14
22
  Thread.current[::BigSession::THREAD_BIG_SESSION_ID_KEY] =
15
23
  value || new_session_id
16
24
  end
25
+ =end
17
26
 
18
27
  def new_session_id
19
28
  SecureRandom.hex(16)
20
29
  end
30
+
31
+ def container
32
+ Thread.current[::BigSession::THREAD_BIG_SESSION_CONTAINER_KEY] ||= []
33
+ end
21
34
  end
22
35
 
23
- private_class_method :new_session_id
36
+ private_class_method :container
24
37
  end
25
38
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BigSession
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_session
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuichiro Someya
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-25 00:00:00.000000000 Z
11
+ date: 2019-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler