lib/lamby/handler.rb in lamby-2.8.0 vs lib/lamby/handler.rb in lamby-3.0.0

- old
+ new

@@ -66,29 +66,36 @@ end private def rack - @rack ||= case @options[:rack] - when :rest, :api - Lamby::RackRest.new @event, @context - when :alb - Lamby::RackAlb.new @event, @context - else - Lamby::RackHttp.new @event, @context + return @rack if defined?(@rack) + @rack = begin + type = rack_option + klass = Lamby::Rack.lookup type, @event + (klass && klass.handle?(@event)) ? klass.new(@event, @context) : false end end + def rack_option + return if ENV['LAMBY_TEST_DYNAMIC_HANDLER'] + @options[:rack] + end + def rack_response rack? ? rack.response(self) : {} end def call_app if Debug.on?(@event) Debug.call @event, @context, rack.env elsif rack? @app.call rack.env + elsif runner? + Runner.call(@event) + elsif lambdakiq? + Lambdakiq.handler(@event) elsif event_bridge? Lamby.config.event_bridge_handler.call @event, @context [200, {}, StringIO.new('')] else [404, {}, StringIO.new('')] @@ -99,14 +106,22 @@ content_encoding_header = hdrs['Content-Encoding'] || '' content_encoding_header.split(', ').any? { |h| ['br', 'gzip'].include?(h) } end def rack? - @event.key?('httpMethod') || @event.dig('requestContext', 'http') + rack end def event_bridge? Lamby.config.event_bridge_handler && @event.key?('source') && @event.key?('detail') && @event.key?('detail-type') + end + + def lambdakiq? + defined?(::Lambdakiq) && ::Lambdakiq.job?(@event) + end + + def runner? + Runner.handle?(@event) end end end