Class: Rack::Bug::RedirectInterceptor
- Inherits:
-
Object
- Object
- Rack::Bug::RedirectInterceptor
- Includes:
- Render
- Defined in:
- lib/rack/bug/redirect_interceptor.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ RedirectInterceptor
constructor
A new instance of RedirectInterceptor.
- #intercept_redirect ⇒ Object
Methods included from Render
#compile, #compile!, #compiled_source, #method_name, #method_name_without_locals, #render_template, #signed_params
Constructor Details
#initialize(app) ⇒ RedirectInterceptor
Returns a new instance of RedirectInterceptor.
6 7 8 |
# File 'lib/rack/bug/redirect_interceptor.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/rack/bug/redirect_interceptor.rb', line 10 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 |
#intercept_redirect ⇒ Object
19 20 21 22 23 |
# File 'lib/rack/bug/redirect_interceptor.rb', line 19 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 |