Class: Hanami::Lambda::Rack Private
- Inherits:
-
Object
- Object
- Hanami::Lambda::Rack
- Defined in:
- lib/hanami/lambda/rack.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Rack interface for AWS Lambda.
Instance Attribute Summary collapse
- #app ⇒ Object readonly private
Instance Method Summary collapse
-
#build_env(event, headers, context) ⇒ Hash
private
Build the Rack environment.
-
#call(event:, context:) ⇒ Hash
private
Handle the request.
-
#initialize(app) ⇒ Rack
constructor
private
Initialize the Rack interface.
Constructor Details
#initialize(app) ⇒ Rack
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the Rack interface
17 18 19 |
# File 'lib/hanami/lambda/rack.rb', line 17 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
12 13 14 |
# File 'lib/hanami/lambda/rack.rb', line 12 def app @app end |
Instance Method Details
#build_env(event, headers, context) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build the Rack environment
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hanami/lambda/rack.rb', line 43 def build_env(event, headers, context) { ::Rack::REQUEST_METHOD => event["httpMethod"], ::Rack::PATH_INFO => event["path"] || "", ::Rack::VERSION => ::Rack::VERSION, ::Rack::RACK_INPUT => StringIO.new(event["body"] || ""), ::Hanami::Lambda::LAMBDA_EVENT => event, ::Hanami::Lambda::LAMBDA_CONTEXT => context }.tap do |env| content_type = headers.delete("Content-Type") || headers.delete("content-type") || headers.delete("CONTENT_TYPE") env["CONTENT_TYPE"] = content_type if content_type end.merge(headers.transform_keys { |k| "HTTP_#{k.upcase.tr('-', '_')}" }) end |
#call(event:, context:) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Handle the request
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hanami/lambda/rack.rb', line 26 def call(event:, context:) headers = event["headers"] || {} env = build_env(event, headers, context) status_code, headers, body = app.call(env) { statusCode: status_code, headers: headers, body: body.join } end |