Class: Protocol::Rack::Request

Inherits:
HTTP::Request
  • Object
show all
Defined in:
lib/protocol/rack/request.rb

Constant Summary collapse

HTTP_UPGRADE =
'HTTP_UPGRADE'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/protocol/rack/request.rb', line 18

def initialize(env)
	@env = env

	super(
		@env['rack.url_scheme'],
		@env['HTTP_HOST'],
		@env['REQUEST_METHOD'],
		@env['PATH_INFO'],
		@env['SERVER_PROTOCOL'],
		self.class.headers(@env),
		Body::InputWrapper.new(@env['rack.input']),
		self.class.protocol(@env)
	)
end

Class Method Details

.[](env) ⇒ Object



14
15
16
# File 'lib/protocol/rack/request.rb', line 14

def self.[](env)
	env['protocol.http.request'] ||= new(env)
end

.headers(env) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/protocol/rack/request.rb', line 43

def self.headers(env)
	headers = ::Protocol::HTTP::Headers.new
	env.each do |key, value|			
		if key.start_with?('HTTP_')
			next if key == 'HTTP_HOST'
			headers[key[5..-1].gsub('_', '-').downcase] = value
		end
	end

	return headers
end

.protocol(env) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/protocol/rack/request.rb', line 35

def self.protocol(env)
	if protocols = env['rack.protocol']
		return Array(protocols)
	elsif protocols = env[HTTP_UPGRADE]
		return protocols.split(/\s*,\s*/)
	end
end