Class: Flame::Dispatcher::Request

Inherits:
Rack::Request
  • Object
show all
Includes:
Memery
Defined in:
lib/flame/dispatcher/request.rb

Overview

Class for requests

Constant Summary collapse

HEADER_PREFIX =
'HTTP_'

Instance Method Summary collapse

Instance Method Details

#headersObject

Helper method for comfortable Camel-Cased Hash of headers



32
33
34
35
36
37
38
39
40
41
# File 'lib/flame/dispatcher/request.rb', line 32

memoize def headers
	env.each_with_object({}) do |(key, value), result|
		next unless key.start_with?(HEADER_PREFIX)

		camelized_key =
			key.delete_prefix(HEADER_PREFIX).downcase.tr('_', '/').camelize.gsub('::', '-')

		result[camelized_key] = value
	end
end

#http_methodObject

Override HTTP-method of the request if the param ‘_method’ found



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flame/dispatcher/request.rb', line 15

memoize def http_method
	method_from_method =
		begin
			params['_method']
		rescue ArgumentError => e
			## https://github.com/rack/rack/issues/337#issuecomment-48555831
			raise unless e.message.include?('invalid %-encoding')
		end

	(method_from_method || request_method).upcase.to_sym
end

#pathObject

Initialize Flame::Path



10
11
12
# File 'lib/flame/dispatcher/request.rb', line 10

memoize def path
	Flame::Path.new path_info
end