Skip to content

Add Rack::Handler::Servlet::DefaultEnv#get_header #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/ruby/rack/handler/servlet/default_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class DefaultEnv < Hash # The environment must be an instance of Hash !
SCRIPT_NAME SERVER_NAME SERVER_PORT SERVER_SOFTWARE).
map!(&:freeze)

attr_reader :env

# Factory method for creating the Hash.
# Besides initializing a new env instance this method by default
# eagerly populates (and returns) the env Hash.
Expand Down Expand Up @@ -60,6 +62,16 @@ def initialize(servlet_env = nil)
end
end

# If a block is given, it yields to the block if the value hasn't been set
# on the request.
def fetch_header(name, &block)
@env.fetch(name, &block)
end

def get_header(key)
@env[key]
end

def populate
unless @populated
populate! if @servlet_env
Expand All @@ -75,6 +87,16 @@ def populate!
self
end

def session_options
fetch_header(RACK_SESSION_OPTIONS) do |k|
set_header RACK_SESSION_OPTIONS, {}
end
end

def set_header(name, v)
@env[name] = v
end

def to_hash(bare = nil)
if bare
{}.update(populate)
Expand Down