Class: Lamby::Handler

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, event, context, options = {}) ⇒ Handler

Returns a new instance of Handler.



13
14
15
16
17
18
# File 'lib/lamby/handler.rb', line 13

def initialize(app, event, context, options = {})
  @app = app
  @event = event
  @context = context
  @options = options
end

Class Method Details

.call(app, event, context, options = {}) ⇒ Object



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

def call(app, event, context, options = {})
  Lamby::ColdStartMetrics.instrument! if Lamby.config.cold_start_metrics?
  new(app, event, context, options).call.response
end

Instance Method Details

#base64_encodeable?(hdrs = @headers) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/lamby/handler.rb', line 52

def base64_encodeable?(hdrs = @headers)
  hdrs && (
    hdrs['content-transfer-encoding'] == 'binary' ||
    hdrs['Content-Transfer-Encoding'] == 'binary' ||
    content_encoding_compressed?(hdrs) ||
    hdrs['X-Lamby-Base64'] == '1'
  )
end

#bodyObject



40
41
42
43
44
45
# File 'lib/lamby/handler.rb', line 40

def body
  @rbody ||= ''.tap do |rbody|
    @body.each { |part| rbody << part.to_s if part }
    @body.close if @body.respond_to? :close
  end
end

#body64Object



61
62
63
# File 'lib/lamby/handler.rb', line 61

def body64
  Base64.strict_encode64(body)
end

#callObject



47
48
49
50
# File 'lib/lamby/handler.rb', line 47

def call
  @response ||= call_app
  self
end

#headersObject



28
29
30
# File 'lib/lamby/handler.rb', line 28

def headers
  @headers
end

#responseObject



20
21
22
# File 'lib/lamby/handler.rb', line 20

def response
  @response
end

#set_cookiesObject



32
33
34
35
36
37
38
# File 'lib/lamby/handler.rb', line 32

def set_cookies
  return @set_cookies if defined?(@set_cookies)
  set_cookie = @headers.delete("Set-Cookie") || @headers.delete("set-cookie")
  @set_cookies = if @headers && set_cookie
    Array(set_cookie).flat_map { |cookie| cookie.split("\n").map(&:strip) }
  end
end

#statusObject



24
25
26
# File 'lib/lamby/handler.rb', line 24

def status
  @status
end