Sha256: 3a4a7b99436232c2744e8ea1cddc4981cb5bad61df86e7d2c9ffe069d4aa9b94

Contents?: true

Size: 741 Bytes

Versions: 16

Compression:

Stored size: 741 Bytes

Contents

module Rack
  class Bug    
    class RedirectInterceptor
      include Render
      
      def initialize(app)
        @app = app
      end
      
      def call(env)
        status, headers, body = @app.call(env)
        @response = Rack::Response.new(body, status, headers)
        if @response.redirect? && env["rack-bug.intercept_redirects"]
          intercept_redirect
        end
        @response.to_a
      end
      
      def intercept_redirect
         new_body = render_template("redirect", :redirect_to => @response.location)
         new_headers = { "Content-Type" => "text/html", "Content-Length" => new_body.size.to_s }
         @response = Rack::Response.new(new_body, 200, new_headers)
       end
      
    end
  end
end

Version data entries

16 entries across 16 versions & 5 rubygems

Version Path
rack-bug-rails-3-0.3.1 lib/rack/bug/redirect_interceptor.rb
rack-bug-rails-3-0.3.0 lib/rack/bug/redirect_interceptor.rb
gentooboontoo-rack-bug-0.3.0.edge lib/rack/bug/redirect_interceptor.rb
wireframe-rack-bug-0.3.1.2 lib/rack/bug/redirect_interceptor.rb
wireframe-rack-bug-0.3.1.1 lib/rack/bug/redirect_interceptor.rb
wireframe-rack-bug-0.3.1 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.1.2 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.1.1 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.1 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.0.4 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.0.3 lib/rack/bug/redirect_interceptor.rb
lrd_rack_bug-0.3.0.2 lib/rack/bug/redirect_interceptor.rb
ghazel-rack-bug-0.3.0.4 lib/rack/bug/redirect_interceptor.rb
ghazel-rack-bug-0.3.0.3 lib/rack/bug/redirect_interceptor.rb
ghazel-rack-bug-0.3.0.2 lib/rack/bug/redirect_interceptor.rb
ghazel-rack-bug-0.3.0.1 lib/rack/bug/redirect_interceptor.rb