lib/contrast/framework/manager.rb in contrast-agent-7.1.0 vs lib/contrast/framework/manager.rb in contrast-agent-7.2.0
- old
+ new
@@ -35,10 +35,13 @@
next unless enable_framework_support?(framework_klass.detection_class)
logger.info('Framework detected. Enabling support.', framework: framework_klass.detection_class)
framework_klass
end
+
+ # Delete Rack if we have more than one framework detected
+ @_frameworks.delete(Contrast::Framework::Rack::Support) if @_frameworks.length > 1
@_frameworks.compact!
end
# Patches that have to be applied as early as possible to catch calls that happen prior to the first Request,
# typically those around configuration.
@@ -85,19 +88,25 @@
#
# @param env [Hash] the various variables stored by this and other Middlewares to know the state and values of
# this particular Request
# @return [::Rack::Request] either a rack request or subclass thereof.
def retrieve_request env
- # If we're mounted on Rails, use Rails.
- if @_frameworks.include?(Contrast::Framework::Rails::Support)
- return Contrast::Framework::Rails::Support.retrieve_request(env)
+ if Contrast::Utils::DuckUtils.empty_duck?(@_frameworks)
+ return Contrast::Framework::Rack::Support.retrieve_request(env)
end
- # If we know the framework, use it.
- return @_frameworks[0].retrieve_request(env) if @_frameworks.length == 1
+ framework = @_frameworks[0]
- # Fall back on a regular Rack::Request
- ::Rack::Request.new(env)
+ case framework.cs__name
+ when 'Contrast::Framework::Rails::Support'
+ Contrast::Framework::Rails::Support.retrieve_request(env)
+ when 'Contrast::Framework::Grape::Support'
+ Contrast::Framework::Grape::Support.retrieve_request(env)
+ when 'Contrast::Framework::Sinatra::Support'
+ Contrast::Framework::Sinatra::Support.retrieve_request(env)
+ else
+ Contrast::Framework::Rack::Support.retrieve_request(env)
+ end
rescue StandardError => e
logger.warn('Unable to retrieve_request', e)
end
# @param env [Hash] the various variables stored by this and other Middlewares to know the state and values of