Class: Rack::ReverseProxy

Inherits:
Object
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation
Defined in:
lib/rack/reverse_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, &b) ⇒ ReverseProxy

Returns a new instance of ReverseProxy.



12
13
14
15
16
17
# File 'lib/rack/reverse_proxy.rb', line 12

def initialize(app = nil, &b)
  @app = app || lambda {|env| [404, [], []] }
  @matchers = []
  @global_options = {:preserve_host => true, :x_forwarded_host => true, :matching => :all, :replace_response_host => false}
  instance_eval(&b) if block_given?
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rack/reverse_proxy.rb', line 19

def call(env)
  rackreq = Rack::Request.new(env)
  matcher = get_matcher(rackreq.fullpath, Proxy.extract_http_request_headers(rackreq.env), rackreq)
  return @app.call(env) if matcher.nil?

  if @global_options[:newrelic_instrumentation]
    action_name = "#{rackreq.path.gsub(/\/\d+/,'/:id').gsub(/^\//,'')}/#{rackreq.request_method}" # Rack::ReverseProxy/foo/bar#GET
    perform_action_with_newrelic_trace(:name => action_name, :request => rackreq) do
      proxy(env, rackreq, matcher)
    end
  else
    proxy(env, rackreq, matcher)
  end
end