<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core/responses.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,7 +6,7 @@ require 'merb-auth-core/authentication'
 require 'merb-auth-core/strategy'
 require 'merb-auth-core/session_mixin'
 require 'merb-auth-core/errors'
-require 'merb-auth-core/redirection'
+require 'merb-auth-core/responses'
 require 'merb-auth-core/authenticated_helper'
 require 'merb-auth-core/customizations'
 require 'merb-auth-core/bootloader'</diff>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,9 +31,9 @@ module Merb
     def ensure_authenticated(*strategies)
       session.authenticate!(request, *strategies) unless session.user
       auth = session.authentication
-      if auth.redirected?
-        redirect auth.redirect_url
-        self.status = auth.redirect_status
+      if auth.halted?
+        self.headers.merge!(auth.headers)
+        self.status  = auth.status
         throw :halt
       end
       session.user</diff>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core/authenticated_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -77,15 +77,17 @@ module Merb
         unless s.abstract?
           strategy = s.new(request)
           user = strategy.run! 
-          if strategy.redirected?
-            redirect!(strategy.redirect_url, strategy.redirect_options)
+          if strategy.halted?
+            self.headers  = strategy.headers
+            self.status   = strategy.status
+            halt!
             return
           end
           user
         end
       end
       raise Merb::Controller::Unauthenticated, msg unless user
-      session.user = user
+      self.user = user
     end
   
     # &quot;Logs Out&quot; a user from the session.  Also clears out all session data</diff>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core/authentication.rb</filename>
    </modified>
    <modified>
      <diff>@@ -132,25 +132,35 @@ module Merb
       #   +:permanent+ Set this to true to make the redirect permanent
       #   +:status+ Set this to an integer for the status to return
       def redirect!(url, opts = {})
-        @redirect_url = url
-        @redirect_opts = opts
+        self.headers[&quot;Location&quot;] = url
+        self.status = opts[:permanent] ? 301 : 302
+        self.status = opts[:status] if opts[:status]
+        halt!
         return true
       end
     
       # Returns ture if the strategy redirected
       def redirected?
-        !!@redirect_url
+        !!headers[&quot;Location&quot;]
       end
+      
+      # Provides a place to put the status of the response
+      attr_accessor :status
     
-      # Returns the redirect_url if it's ben set
-      def redirect_url
-        @redirect_url
+      # Provides a place to put headers
+      def headers
+        @headers ||={}
       end
-    
-      # Returns the redirect options set in the strategy
-      # or a blank hash
-      def redirect_options
-        @redirect_opts ||= {}
+      
+      # Mark this strategy as complete for this request.  Will cause that no other
+      # strategies will be executed.  
+      def halt!
+        @halt = true
+      end
+      
+      # Checks to see if this strategy has been halted
+      def halted?
+        !!@halt
       end
     
       # This is the method that is called as the test for authentication and is where</diff>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core/strategy.rb</filename>
    </modified>
    <modified>
      <diff>@@ -7,11 +7,23 @@ describe &quot;Merb::AuthenticationHelper&quot; do
   end
   
   before(:each) do
+    clear_strategies!
     @controller = ControllerMock.new(fake_request)
     @request = @controller.request
     @session = @controller.session
-    @controller.stub!(:session).and_return(@session)
-    @session.stub!(:user).and_return(&quot;WINNA&quot;)
+    @session.user = &quot;WINNA&quot;
+    Viking.captures.clear
+    
+    class Kone &lt; Merb::Authentication::Strategy
+      def run!
+        puts params.inspect
+        Viking.capture(self.class)
+        params[self.class.name]
+      end
+    end
+    
+    class Ktwo &lt; Kone; end
+    
   end
   
   it &quot;should not raise and Unauthenticated error&quot; do
@@ -37,19 +49,10 @@ describe &quot;Merb::AuthenticationHelper&quot; do
   it &quot;should accept and execute the provided strategies&quot; do
     # This allows using a before filter with specific arguments
     # before :ensure_authenticated, :with =&gt; [Authenticaiton::OAuth, Merb::Authentication::BasicAuth]
-    M1 = mock(&quot;m1&quot;)
-    M2 = mock(&quot;m2&quot;)
-    M1.stub!(:new).and_return(M1)
-    M2.stub!(:new).and_return(M2)
-    M1.should_receive(:abstract?).and_return(false)
-    M2.should_receive(:abstract?).and_return(false)
-    M1.should_receive(:run!).ordered.and_return(false)
-    M2.should_receive(:run!).ordered.and_return(&quot;WINNA&quot;)
-    M1.should_receive(:redirected?).and_return false
-    M2.should_receive(:redirected?).and_return false
     controller = ControllerMock.new(fake_request)
-    controller.session.should_receive(:user).and_return(nil, &quot;WINNA&quot;)
-    controller.send(:ensure_authenticated, [M1, M2])
+    controller.request.params[&quot;Ktwo&quot;] = true
+    controller.send(:ensure_authenticated, Kone, Ktwo)
+    Viking.captures.should == %w( Kone Ktwo )
   end
   
   describe &quot;redirection&quot; do</diff>
      <filename>merb-auth/merb-auth-core/spec/helpers/authentication_helper_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -159,62 +159,49 @@ describe &quot;Merb::Authentication Session&quot; do
     before(:each) do
       class Sone &lt; Merb::Authentication::Strategy
         def run!
+          Viking.capture(Sone)
+          params[:pass_1]
         end
       end
       class Stwo &lt; Merb::Authentication::Strategy
         def run!
+          Viking.capture(Stwo) 
+          params[:pass_2]
         end
       end
       class Sthree &lt; Merb::Authentication::Strategy
         def run!
-          &quot;WINNA&quot;
+          Viking.capture(Sthree)
+          params[:pass_3] 
         end
       end
       class Sfour &lt; Merb::Authentication::Strategy
         abstract!
         
         def run!
-          &quot;BAD&quot;
+           &quot;BAD MAN&quot;
         end
       end
       
       Sfour.should_not_receive(:run!)
       @request = Users.new(fake_request)
       @auth = Merb::Authentication.new(@request.session)
-      Merb::Authentication.stub!(:new).and_return(@auth)
+      Viking.captures.clear
     end
     
     it &quot;should execute the strategies in the default order&quot; do
-      s1 = mock(&quot;s1&quot;)
-      s2 = mock(&quot;s2&quot;)
-      Sone.should_receive(:new).with(@request).and_return(s1)
-      Stwo.should_receive(:new).with(@request).and_return(s2)
-      s1.should_receive(:run!).ordered.and_return(nil)
-      s2.should_receive(:run!).ordered.and_return(&quot;WIN&quot;)
-      s1.should_receive(:redirected?).and_return false
-      s2.should_receive(:redirected?).and_return false
+      @request.params[:pass_3] = true
       @auth.authenticate!(@request)
+      Viking.captures.should == %w( Sone Stwo Sthree )
     end
     
     it &quot;should run the strategeis until if finds a non nil non false&quot; do
-      s1 = mock(&quot;s1&quot;)
-      s2 = mock(&quot;s2&quot;)
-      s3 = mock(&quot;s3&quot;)
-      Sone.should_receive(:new).with(@request).and_return(s1)
-      Stwo.should_receive(:new).with(@request).and_return(s2)
-      Sthree.should_receive(:new).with(@request).and_return(s3)
-      s1.should_receive(:run!).ordered.and_return(nil)
-      s2.should_receive(:run!).ordered.and_return(false)
-      s3.should_receive(:run!).ordered.and_return(&quot;WIN&quot;)
-      [s1,s2,s3].each{|s| s.should_receive(:redirected?).and_return(false)}
+      @request.params[:pass_2] = true
       @auth.authenticate!(@request)
+      Viking.captures.should == %w( Sone Stwo )
     end
     
     it &quot;should raise an Unauthenticated exception if no 'user' is found&quot; do
-      s3 = mock(&quot;s3&quot;)
-      Sthree.stub!(:new).and_return(s3)
-      s3.should_receive(:run!).and_return(nil)
-      s3.should_receive(:redirected?).and_return(false)
       lambda do
         @auth.authenticate!(@request)
       end.should raise_error(Merb::Controller::Unauthenticated)
@@ -222,32 +209,21 @@ describe &quot;Merb::Authentication Session&quot; do
     
     it &quot;should store the user into the session if one is found&quot; do
       @auth.should_receive(:user=).with(&quot;WINNA&quot;)
+      @request.params[:pass_1] = &quot;WINNA&quot;
       @auth.authenticate!(@request)
     end
     
     it &quot;should use the Authentiation#error_message as the error message&quot; do
       @auth.should_receive(:error_message).and_return(&quot;BAD BAD BAD&quot;)
-      s3 = mock(&quot;s3&quot;, :null_object =&gt; true)
-      s3.stub!(:run!).and_return(false)
-      s3.stub!(:redirected?).and_return(false)
-      Sthree.stub!(:new).and_return(s3)
       lambda do
         @auth.authenticate!(@request)
       end.should raise_error(Merb::Controller::Unauthenticated, &quot;BAD BAD BAD&quot;)
     end
     
     it &quot;should execute the strategies as passed into the authenticate! method&quot; do
-      m1 = mock(&quot;strategy 1&quot;)
-      m2 = mock(&quot;strategy 2&quot;)
-      m1.stub!(:abstract?).and_return(false)
-      m2.stub!(:abstract?).and_return(false)
-      m1.should_receive(:new).and_return(m1)
-      m2.should_receive(:new).and_return(m2)
-      m2.should_receive(:run!).ordered
-      m1.should_receive(:run!).ordered.and_return(&quot;WINNA&quot;)
-      m1.stub!(:redirected?).and_return(false)
-      m2.stub!(:redirected?).and_return(false)
-      @auth.authenticate!(@request, m2, m1)
+      @request.params[:pass_1] = true
+      @auth.authenticate!(@request, Stwo, Sone)
+      Viking.captures.should == [&quot;Stwo&quot;, &quot;Sone&quot;]
     end
     
   end
@@ -298,22 +274,21 @@ describe &quot;Merb::Authentication Session&quot; do
     it &quot;should answer redirected true if the strategy did redirect&quot; do
       @request.params[:url] = &quot;/some/url&quot;
       @a.authenticate! @request
-      @a.should be_redirected
+      @a.halted?
     end
     
-    it &quot;should provide access to the redirect_url&quot; do
+    it &quot;should provide access to the Headers&quot; do
       @request.params[:url] = &quot;/some/url&quot;
       @a.authenticate! @request
-      @a.should be_redirected
-      @a.redirect_url.should == &quot;/some/url&quot;
+      @a.headers.should == {&quot;Location&quot; =&gt; &quot;/some/url&quot;}
     end
     
-    it &quot;should provide access to the redirect_options&quot; do
+    it &quot;should provide access to the status&quot; do
       @request.params[:url] = &quot;/some/url&quot;
       @request.params[:status] = 401
       @a.authenticate! @request
-      @a.should be_redirected
-      @a.redirect_options.should == {:status =&gt; 401}
+      @a.should be_halted
+      @a.status.should == 401
     end
     
     it &quot;should stop processing the strategies if one redirects&quot; do
@@ -321,9 +296,11 @@ describe &quot;Merb::Authentication Session&quot; do
       lambda do
         @a.authenticate! @request, MyStrategy, FailStrategy
       end.should_not raise_error(Merb::Controller::NotFound)
-      @a.should be_redirected
+      @a.should be_halted
       @request.params[:should_not_be_here].should be_nil
     end
   end
+  
+
 
 end
\ No newline at end of file</diff>
      <filename>merb-auth/merb-auth-core/spec/merb-auth-core/authentication_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -195,27 +195,33 @@ describe &quot;Merb::Authentication::Strategy&quot; do
     
     it &quot;allow for a redirect!&quot; do
       @s.redirect!(&quot;/somewhere&quot;)
-      @s.redirect_url.should == &quot;/somewhere&quot;
+      @s.headers[&quot;Location&quot;].should == &quot;/somewhere&quot;
     end
     
-    it &quot;should set redirect_options as an empty hash&quot; do
-      @s.redirect!(&quot;/somewhere&quot;)
-      @s.redirect_options.should == {}
+    it &quot;should provide access to setting the headers&quot; do
+      @s.headers[&quot;Location&quot;] = &quot;/a/url&quot;
+      @s.headers[&quot;Location&quot;].should == &quot;/a/url&quot;
+    end
+    
+    it &quot;should allow access to the setting header&quot; do
+      @s.status = 403
+      @s.status.should == 403
     end
     
-    it &quot;should return nil for the redirect_url if it is not redirected&quot; do
+    it &quot;should return nil for the Location if it is not redirected&quot; do
       @s.should_not be_redirected
-      @s.redirect_url.should be_nil
+      @s.headers[&quot;Location&quot;].should be_nil
     end
       
     it &quot;should pass through the options to the redirect options&quot; do
       @s.redirect!(&quot;/somewhere&quot;, :status =&gt; 401)
-      @s.redirect_options.should == {:status =&gt; 401}
+      @s.headers[&quot;Location&quot;].should == &quot;/somewhere&quot;
+      @s.status.should == 401
     end
     
     it &quot;should set a redirect with a permanent true&quot; do
       @s.redirect!(&quot;/somewhere&quot;, :permanent =&gt; true)
-      @s.redirect_options.should == {:permanent =&gt; true}
+      @s.status.should == 301
     end
     
     it &quot;should be redirected?&quot; do
@@ -224,6 +230,17 @@ describe &quot;Merb::Authentication::Strategy&quot; do
       @s.should be_redirected
     end
     
+    it &quot;should set the strategy to halted&quot; do
+      @s.redirect!(&quot;/somewhere&quot;)
+      @s.should be_halted
+    end
+    
+    it &quot;should halt a strategy&quot; do
+      @s.should_not be_halted
+      @s.halt!
+      @s.should be_halted
+    end
+    
   end
   
   describe &quot;register strategies&quot; do</diff>
      <filename>merb-auth/merb-auth-core/spec/merb-auth-core/strategy_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -80,3 +80,14 @@ class Merb::Authentication
 end
 
 Merb::Authentication.user_class = User
+
+class Viking
+  def self.captures
+    @captures ||= []
+  end
+  
+  def self.capture(klass)
+    @captures ||= []
+    @captures &lt;&lt; klass.name
+  end
+end</diff>
      <filename>merb-auth/merb-auth-core/spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>merb-auth/merb-auth-core/lib/merb-auth-core/redirection.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>6c8c60d4798fc75f3429a81bb32b637bfafaf19d</id>
    </parent>
  </parents>
  <author>
    <name>Daniel Neighman</name>
    <email>has.sox@gmail.com</email>
  </author>
  <url>http://github.com/wycats/merb-more/commit/c098537a2179f4bbcad4305fd71fee0fde0d0fd9</url>
  <id>c098537a2179f4bbcad4305fd71fee0fde0d0fd9</id>
  <committed-date>2008-10-10T04:16:37-07:00</committed-date>
  <authored-date>2008-10-10T04:16:37-07:00</authored-date>
  <message>Adds capacity to set headers and status in the strategies.  throw(:halt should not be used in strategies :) Win!</message>
  <tree>b40326ebf54c253e9fb39ff5289dfc707bd940d7</tree>
  <committer>
    <name>Daniel Neighman</name>
    <email>has.sox@gmail.com</email>
  </committer>
</commit>
