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.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/protocol/rack/request.rb', line 34

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



30
31
32
# File 'lib/protocol/rack/request.rb', line 30

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

.headers(env) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/protocol/rack/request.rb', line 59

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



51
52
53
54
55
56
57
# File 'lib/protocol/rack/request.rb', line 51

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