lib/lamby/handler.rb in lamby-3.1.1 vs lib/lamby/handler.rb in lamby-3.1.2
- old
+ new
@@ -12,17 +12,14 @@
def initialize(app, event, context, options = {})
@app = app
@event = event
@context = context
@options = options
- @called = false
end
def response
- { statusCode: status,
- headers: headers,
- body: body }.merge(rack_response)
+ @response
end
def status
@status
end
@@ -44,14 +41,11 @@
@body.close if @body.respond_to? :close
end
end
def call
- return self if @called
- @status, @headers, @body = call_app
- set_cookies if rack?
- @called = true
+ @response ||= call_app
self
end
def base64_encodeable?(hdrs = @headers)
hdrs && (
@@ -80,24 +74,28 @@
return if ENV['LAMBY_TEST_DYNAMIC_HANDLER']
@options[:rack]
end
def rack_response
- rack? ? rack.response(self) : {}
+ { statusCode: status,
+ headers: headers,
+ body: body }.merge(rack.response(self))
end
def call_app
if Debug.on?(@event)
Debug.call @event, @context, rack.env
elsif rack?
- @app.call rack.env
+ @status, @headers, @body = @app.call rack.env
+ set_cookies
+ rack_response
elsif runner?
- Runner.call(@event)
+ @status, @headers, @body = Runner.call(@event)
+ { statusCode: status, headers: headers, body: body }
elsif lambdakiq?
Lambdakiq.handler(@event)
elsif event_bridge?
Lamby.config.event_bridge_handler.call @event, @context
- [200, {}, StringIO.new('')]
else
[404, {}, StringIO.new('')]
end
end