summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2016-01-16 09:47:04 -0500
committereileencodes <eileencodes@gmail.com>2016-01-16 15:17:51 -0500
commit45acf493f153bac95fa486bc5a8633baaa9e49e4 (patch)
treee9e912bfcd449ba5adcb9d719836f43411885b1f
parent545532b01d332325c913808b7c2047a9256ed551 (diff)
downloadrack-45acf493f153bac95fa486bc5a8633baaa9e49e4.tar.gz
Move empty hash to it's own method for session
This sets the session's default to a new method called `default_session` which is set to an empty hash. Now we can depend on the `default_session` method rather than depending on the implementation of `Hash`.
-rw-r--r--lib/rack/request.rb4
-rw-r--r--test/spec_request.rb5
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index 50dba475..a76f15cd 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -160,7 +160,7 @@ module Rack
def session
fetch_header(RACK_SESSION) do |k|
- set_header RACK_SESSION, {}
+ set_header RACK_SESSION, default_session
end
end
@@ -439,6 +439,8 @@ module Rack
private
+ def default_session; {}; end
+
def parse_http_accept_header(header)
header.to_s.split(/\s*,\s*/).map do |part|
attribute, parameters = part.split(/\s*;\s*/, 2)
diff --git a/test/spec_request.rb b/test/spec_request.rb
index 2062e246..74f2fa87 100644
--- a/test/spec_request.rb
+++ b/test/spec_request.rb
@@ -1305,6 +1305,11 @@ EOF
req.trusted_proxy?("2001:470:1f0b:18f8::1").must_equal nil
end
+ it "sets the default session to an empty hash" do
+ req = make_request(Rack::MockRequest.env_for("http://example.com:8080/"))
+ assert_equal Hash.new, req.session
+ end
+
class MyRequest < Rack::Request
def params
{:foo => "bar"}