Class: Lamby::RackAlb

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

Constant Summary

Constants inherited from Rack

Lamby::Rack::HTTP_X_REQUESTID, Lamby::Rack::LAMBDA_CONTEXT, Lamby::Rack::LAMBDA_EVENT

Instance Attribute Summary

Attributes inherited from Rack

#context, #event

Instance Method Summary collapse

Methods inherited from Rack

#api?, #env, #initialize

Methods included from SamHelpers

#sam_local?

Constructor Details

This class inherits a constructor from Lamby::Rack

Instance Method Details

#alb?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/lamby/rack_alb.rb', line 4

def alb?
  true
end

#multi_value?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/lamby/rack_alb.rb', line 8

def multi_value?
  event.key? 'multiValueHeaders'
end

#response(handler) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lamby/rack_alb.rb', line 12

def response(handler)
  hhdrs = handler.headers
  multivalue_headers = hhdrs.transform_values { |v| Array.wrap(v) } if multi_value?
  status_description = "#{handler.status} #{::Rack::Utils::HTTP_STATUS_CODES[handler.status]}"
  base64_encode = hhdrs['Content-Transfer-Encoding'] == 'binary' || hhdrs['X-Lamby-Base64'] == '1'
  body = Base64.strict_encode64(handler.body) if base64_encode
  { multiValueHeaders: multivalue_headers,
    statusDescription: status_description,
    isBase64Encoded: base64_encode,
    body: body }.compact
end