Class: Lamby::RackHttp

Inherits:
Rack
  • Object
show all
Defined in:
lib/lamby/rack_http.rb

Constant Summary

Constants inherited from Rack

Lamby::Rack::HTTP_COOKIE, Lamby::Rack::HTTP_X_REQUESTID, Lamby::Rack::HTTP_X_REQUEST_START, Lamby::Rack::LAMBDA_CONTEXT, Lamby::Rack::LAMBDA_EVENT

Instance Attribute Summary

Attributes inherited from Rack

#context, #event

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rack

#env, #initialize, lookup, #multi_value?, types

Constructor Details

This class inherits a constructor from Lamby::Rack

Class Method Details

.handle?(event) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
# File 'lib/lamby/rack_http.rb', line 6

def handle?(event)
  event.key?('version') && 
    ( event.dig('requestContext', 'http') || 
      event.dig('requestContext', 'httpMethod') )
end

Instance Method Details

#response(handler) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lamby/rack_http.rb', line 14

def response(handler)
  if handler.base64_encodeable?
    { isBase64Encoded: true, body: handler.body64 }
  else
    super
  end.tap do |r|
    if cookies = handler.set_cookies
      if payload_version_one?
        r[:multiValueHeaders] ||= {}
        r[:multiValueHeaders]['Set-Cookie'] = cookies
      else
        r[:cookies] = cookies
      end
    end
  end
end