Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a4f30d2
commit cc1d162
Showing
5 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,20 @@ def empty?; true; end | |
def nil?; true; end | ||
end | ||
|
||
class SessionId | ||
attr_reader :public_id | ||
|
||
def initialize(public_id) | ||
@public_id = public_id | ||
end | ||
|
||
alias :cookie_value :public_id | ||
|
||
def empty?; false; end | ||
def to_s; raise; end | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vincentwoo
|
||
def inspect; public_id.inspect; end | ||
end | ||
|
||
module Abstract | ||
# SessionHash is responsible to lazily load the session from store. | ||
|
||
|
@@ -64,7 +78,11 @@ def each(&block) | |
|
||
def [](key) | ||
load_for_read! | ||
@data[key.to_s] | ||
if key == "session_id" | ||
id.public_id | ||
else | ||
@data[key.to_s] | ||
end | ||
end | ||
|
||
def fetch(key, default = Unspecified, &block) | ||
|
@@ -262,11 +280,13 @@ def initialize_sid | |
# Monkey patch this to use custom methods for session id generation. | ||
|
||
def generate_sid(secure = @sid_secure) | ||
if secure | ||
public_id = if secure | ||
secure.hex(@sid_length) | ||
else | ||
"%0#{@sid_length}x" % Kernel.rand(2**@sidbits - 1) | ||
end | ||
|
||
SessionId.new(public_id) | ||
rescue NotImplementedError | ||
generate_sid(false) | ||
end | ||
|
@@ -296,7 +316,7 @@ def load_session(req) | |
def extract_session_id(request) | ||
sid = request.cookies[@key] | ||
sid ||= request.params[@key] unless @cookie_only | ||
sid || NullSessionId.new | ||
(sid && SessionId.new(sid)) || NullSessionId.new | ||
end | ||
|
||
# Returns the current session id from the SessionHash. | ||
|
@@ -367,7 +387,7 @@ def commit_session(req, res) | |
req.get_header(RACK_ERRORS).puts("Deferring cookie for #{session_id}") if $VERBOSE | ||
else | ||
cookie = Hash.new | ||
cookie[:value] = data | ||
cookie[:value] = data.cookie_value | ||
cookie[:expires] = Time.now + options[:expire_after] if options[:expire_after] | ||
cookie[:expires] = Time.now + options[:max_age] if options[:max_age] | ||
set_cookie(req, res, cookie.merge!(options)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tenderlove Hi, I know this commit has been a while. But why are we preventing this coercion to string here? It seems to be breaking things here. thanks