Class: Protocol::Rack::Request

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



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

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



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

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

.headers(env) ⇒ Object



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

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



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

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