Class: Rack::Insight::RedirectInterceptor
- Inherits:
-
Object
- Object
- Rack::Insight::RedirectInterceptor
- Includes:
- Render
- Defined in:
- lib/rack/insight/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
Methods included from Logging
Constructor Details
#initialize(app) ⇒ RedirectInterceptor
Returns a new instance of RedirectInterceptor.
5 6 7 |
# File 'lib/rack/insight/redirect_interceptor.rb', line 5 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/rack/insight/redirect_interceptor.rb', line 9 def call(env) status, headers, body = @app.call(env) @response = Rack::Response.new(body, status, headers) if @response.redirect? && env["rack-insight.intercept_redirects"] intercept_redirect end @response.to_a end |
#intercept_redirect ⇒ Object
18 19 20 21 22 |
# File 'lib/rack/insight/redirect_interceptor.rb', line 18 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 |