Skip to content

Refactor to add Rack env builder #4

@elct9620

Description

@elct9620

The Rack env build method is too large that hard to extend new behaviors. Add Hanami::Lambda::Env to improve it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions