Sha256: 3b2fb0c8b92f8778f7fa72d298360b073afc4646ee9cb98400c45035469efffd

Contents?: true

Size: 1.52 KB

Versions: 6

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'rack'
require 'fake_server'
require 'new_relic/rack/agent_hooks'

require 'json' if RUBY_VERSION >= '1.9'

module NewRelic
  class FakeExternalServer < FakeServer

    STATUS_MESSAGE = "<html><head><title>FakeExternalServer status</title></head>" +
      "<body>The FakeExternalServer is rockin'</body></html>"

    attr_reader :overridden_response_headers

    def initialize( * )
      super
      @requests = []
    end

    attr_reader :requests

    def call(env)
      @requests << env.dup

      req = ::Rack::Request.new(env)
      res = ::Rack::Response.new
      res.status = req.params["status"].to_i if req.params["status"]

      in_transaction('test') do
        res.write STATUS_MESSAGE
      end
      res.finish
    end

    def reset
      @requests.clear
      @overridden_response_headers = {}
    end

    def override_response_headers(headers)
      @overridden_response_headers.merge!(headers)
    end

    def app
      inner_app = NewRelic::Rack::AgentHooks.new(self)
      server = self
      Proc.new do |env|
        result = inner_app.call(env)
        result[1].merge!(server.overridden_response_headers)
        result
      end
    end

    def fallback_port
      # Only use fallback port on the FakeCollector....
      nil
    end
  end

  class FakeSecureExternalServer < FakeExternalServer
    def initialize
      super(0, true)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
newrelic_rpm-3.9.6.257 test/new_relic/fake_external_server.rb
newrelic_rpm-3.9.5.251 test/new_relic/fake_external_server.rb
newrelic_rpm-3.9.4.245 test/new_relic/fake_external_server.rb
newrelic_rpm-3.9.3.241 test/new_relic/fake_external_server.rb
newrelic_rpm-3.9.2.239 test/new_relic/fake_external_server.rb
newrelic_rpm-3.9.1.236 test/new_relic/fake_external_server.rb