Class: Jets::Controller::RackAdapter::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/controller/rack_adapter/env.rb

Instance Method Summary collapse

Constructor Details

#initialize(event, context, options = {}) ⇒ Env

Returns a new instance of Env.



8
9
10
# File 'lib/jets/controller/rack_adapter/env.rb', line 8

def initialize(event, context, options={})
  @event, @context, @options = event, context, options
end

Instance Method Details

#convertObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jets/controller/rack_adapter/env.rb', line 12

def convert
  options = {}
  options = add_top_level(options)
  options = add_http_headers(options)
  path = path_with_base_path || @event['path'] || '/' # always set by API Gateway but might not be when testing shim, so setting it to make testing easier

  # In case of non-ascii characters, CGI.escape will escape them
  # IE: get '/ほげ'
  # This just because MockRequest.env_for uses URI.parse which does not
  # escape non-ascii characters and throws an error
  unescaped_path = path
  path = path.chars.map { |char| char.ascii_only? ? char : CGI.escape(char) }.join
  env = Rack::MockRequest.env_for(path, options)
  env['PATH_INFO'] = unescaped_path
  # env['QUERY_STRING'] = query_string
  env
end