Class: Jets::Shim::Adapter::Lambda

Inherits:
Web
  • Object
show all
Defined in:
lib/jets/shim/adapter/lambda.rb

Instance Attribute Summary

Attributes inherited from Base

#context, #event, #target

Instance Method Summary collapse

Methods inherited from Web

#base_env, #body, #content_length, #handle, #headers, #headers_env, #host, #http_cookie, #https, #remote_addr, #request_uri, #shim_host, #special_headers, #to_rack_env, #translate_response

Methods inherited from Base

#initialize

Methods included from Util::Logging

#log

Constructor Details

This class inherits a constructor from Jets::Shim::Adapter::Base

Instance Method Details

#envObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/shim/adapter/lambda.rb', line 3

def env
  {
    # Request env keys
    "HTTP_HOST" => host,
    "HTTP_PORT" => headers["x-forwarded-port"],
    "HTTPS" => https,
    "PATH_INFO" => path_info,
    "QUERY_STRING" => query_string,
    "REQUEST_METHOD" => event.dig("requestContext", "http", "method") || "GET", # useful to default to GET when testing with Lambda console
    "REQUEST_PATH" => path_info,
    "SCRIPT_NAME" => "",
    "SERVER_NAME" => host,
    "SERVER_PORT" => headers["x-forwarded-proto"],
    "SERVER_PROTOCOL" => event.dig("requestContext", "http", "protocol") || "HTTP/1.1"
  }
end

#handle?Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/jets/shim/adapter/lambda.rb', line 20

def handle?
  host =~ /lambda-url/ ||
    event["version"] && event["routeKey"]
end