Skip to content

Commit

Permalink
Merge pull request #119 from ka8725/master
Browse files Browse the repository at this point in the history
Ready for Rack::Response Thanks!
  • Loading branch information
Daniel Neighman committed Dec 9, 2015
2 parents cb09b95 + ead4db5 commit b3c7c66
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
warden (1.2.2)
warden (1.2.3)
rack (>= 1.0)

GEM
Expand Down Expand Up @@ -30,3 +30,6 @@ DEPENDENCIES
rake
rspec (~> 2)
warden!

BUNDLED WITH
1.10.6
16 changes: 11 additions & 5 deletions lib/warden/manager.rb
Expand Up @@ -38,13 +38,11 @@ def call(env) # :nodoc:
result ||= {}
case result
when Array
if result.first == 401 && intercept_401?(env)
process_unauthenticated(env)
else
result
end
handle_chain_result(result.first, result, env)
when Hash
process_unauthenticated(env, result)
when Rack::Response
handle_chain_result(result.status, result, env)
end
end

Expand Down Expand Up @@ -95,6 +93,14 @@ def serialize_from_session(scope = nil, &block)

private

def handle_chain_result(status, result, env)
if status == 401 && intercept_401?(env)
process_unauthenticated(env)
else
result
end
end

def intercept_401?(env)
config[:intercept_401] && !env['warden'].custom_failure?
end
Expand Down
16 changes: 15 additions & 1 deletion spec/warden/manager_spec.rb
Expand Up @@ -142,7 +142,7 @@ def call(env)
action = nil

failure = lambda do |_env|
action = _env['PATH_INFO']
action = _env['PATH_INFO']
[401, {}, ['fail']]
end

Expand Down Expand Up @@ -291,6 +291,20 @@ def authenticate!
end
end

describe "app returns Rack::Response" do
it "should return it" do
RAS.add(:foobar) do
def authenticate!
custom!(Rack::Response.new(['body'], 201, {"Content-Type" => "text/plain"}))
end
end
result = @app.call(env_with_params)
result.status.should be(201)
result.body.should eq(['body'])
result.header['Content-Type'].should eq('text/plain')
end
end

describe "success" do
it "should pass through to the application when there is success" do
RAS.add(:foobar) do
Expand Down

0 comments on commit b3c7c66

Please sign in to comment.