Class: Jets::Controller::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/jets/controller/request.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, context) ⇒ Request

Returns a new instance of Request.



5
6
7
8
# File 'lib/jets/controller/request.rb', line 5

def initialize(event, context)
  @event, @context = event, context
  super(env)
end

Instance Method Details

#envObject



10
11
12
# File 'lib/jets/controller/request.rb', line 10

def env
  @env ||= Jets::Controller::Rack::Env.new(@event, @context).convert # convert to Rack env
end

#headersObject

API Gateway is inconsistent about how it cases it keys. Sometimes it is “x-requested-with” vs “X-Requested-With” Normalize it with downcase.



24
25
26
27
# File 'lib/jets/controller/request.rb', line 24

def headers
  headers = @event["headers"] || {}
  headers.transform_keys { |key| key.downcase }
end

#set_env!(env) ⇒ Object

When request hits the middleware Controller::Rack::Middleware::Main endpoint We set the it with the updated env since it could had been mutated down the middleware stack.



17
18
19
# File 'lib/jets/controller/request.rb', line 17

def set_env!(env)
  @env = env
end