Class: Jets::Shim::Response::Base

Inherits:
Object
  • Object
show all
Includes:
Util::Logging, Util::Truthy
Defined in:
lib/jets/shim/response/base.rb

Direct Known Subclasses

Apigw, Lambda, Web

Instance Method Summary collapse

Methods included from Util::Truthy

#truthy?

Methods included from Util::Logging

#log

Constructor Details

#initialize(triplet) ⇒ Base

Returns a new instance of Base.



13
14
15
# File 'lib/jets/shim/response/base.rb', line 13

def initialize(triplet)
  @triplet = triplet
end

Instance Method Details

#translateObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jets/shim/response/base.rb', line 20

def translate
  status, headers, rack_body = @triplet
  headers.merge!(prewarm_headers)
  cookies = handle_set_cookie!(headers)
  stringify_values!(headers)
  body = translate_body(rack_body)
  base64 = base64_encode?(headers)
  if base64
    body = Base64.strict_encode64(body)
  end
  resp = {
    statusCode: status,
    headers: headers, # response headers
    body: body,
    cookies: cookies,
    isBase64Encoded: base64
  }.delete_if { |k, v| v.nil? }
  show_debug_shim_resp(resp)
  resp
end