ncr / rack-proxy

A request/response rewriting HTTP proxy. A Rack app.
MIT License
269 stars 94 forks source link

undefined method `fetch' for #<NewRelic::Rack::DeveloperMode> #53

Closed bogdanRada closed 8 years ago

bogdanRada commented 8 years ago

It seems this gem is incompatible with Newrelic gem Here is some backtrace:

/home/raul/.rvm/gems/ruby-2.1.5/gems/rack-proxy-0.5.17/lib/rack/proxy.rb:43:in `initialize': undefined method `fetch' for #<NewRelic::Rack::DeveloperMode:0x00000004595ae8> (NoMethodError)
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:43:in `new'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:43:in `build'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/newrelic_rpm-3.12.0.288/lib/new_relic/agent/instrumentation/rails_middleware.rb:29:in `build_with_new_relic'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:118:in `block in build'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:118:in `each'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:118:in `inject'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/actionpack-4.2.4/lib/action_dispatch/middleware/stack.rb:118:in `build'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/engine.rb:502:in `app'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/application/finisher.rb:34:in `block in <module:Finisher>'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `run'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `call'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
    from /home/raul/.rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/initializable.rb:54:in `run_initializers'
    from /home/raul/.rvm/gems/ruby-2.1.5/gems/railties-4.2.4/lib/rails/application.rb:352:in `initialize!

Any ideas how to make it work?

I used this proxy class:

class RackPhpProxy < Rack::Proxy

  def rewrite_env(env)
    request = Rack::Request.new(env)
    if request.path =~ %r{\.php}
      env["HTTP_HOST"] = "localhost"
      env["REQUEST_PATH"] = "/php/#{request.fullpath}"
    end
    env
  end
end
bogdanRada commented 8 years ago

i think is happening probably because the initialize method should receive first argument the application and then the options hash.

bogdanRada commented 8 years ago

if i redefine the initialize method from Rack::Proxy like this:


class RackPhpProxy < Rack::Proxy
  def initialize(app = nil, opts= {})
    @app = app
    super(opts)
  end

   def rewrite_env(env)
    request = Rack::Request.new(env)
    if request.path =~ %r{\.php}
      env["HTTP_HOST"] = "localhost"
      env["REQUEST_PATH"] = "/php/#{request.fullpath}"
    end
    env
  end
end

The issue dissapears , but instead the connection fails to localhost with timeout, but that probably is just my configuration wrong or something.

I think should be fixed in the gem itself.

bogdanRada commented 8 years ago

any update on this?

bogdanRada commented 8 years ago

is this repository still maintained?

bogdanRada commented 8 years ago

i am closing this as it seem the repository is not maintained anymore :( too bad, i really wanted to use this in one of my projects.

ncr commented 8 years ago

Hi Bogdan,

Somehow I stopped getting email updates for this repo. Feel free to send a PR, I'll be happy to merge it.

bogdanRada commented 8 years ago

thanks for responding. I have added pull request #55 . :)