Class: Jets::Shim::Adapter::Apigw

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

Direct Known Subclasses

Alb

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



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

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["httpMethod"] || "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-Port"],
    "SERVER_PROTOCOL" => event.dig("requestContext", "protocol") || "HTTP/1.1"
  }
end

#handle?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/jets/shim/adapter/apigw.rb', line 25

def handle?
  host =~ /execute-api/ ||
    event["resource"] && event.dig("requestContext", "stage")
end

#path_infoObject



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

def path_info
  event["path"] || "/" # always set by API Gateway, but setting to make shim testing easier
end