Class: Steam::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/steam/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env = {}) ⇒ Request

Returns a new instance of Request.



30
31
32
33
# File 'lib/steam/request.rb', line 30

def initialize(env = {})
  super(self.class.default_env)
  update(env)
end

Instance Attribute Details

#methodObject

Returns the value of attribute method.



7
8
9
# File 'lib/steam/request.rb', line 7

def method
  @method
end

Class Method Details

.default_envObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/steam/request.rb', line 10

def default_env
  @default_env ||= {
    'REQUEST_METHOD'    => 'GET',
    'SERVER_NAME'       => Steam.config[:server_name],
    'SERVER_PORT'       => Steam.config[:server_port],
    'rack.url_scheme'   => Steam.config[:url_scheme],
    'rack.version'      => [0, 1],
    'rack.input'        => StringIO.new,
    'rack.errors'       => StringIO.new,
    'rack.multithread'  => true,
    'rack.multiprocess' => true,
    'rack.run_once'     => false,
    'rack.test.scheme'  => Steam.config[:url_scheme],
    'rack.test.host'    => 'www.example.com',
    'rack.test.cache_classes' => true
  }
  @default_env.dup
end

Instance Method Details

#envObject



39
40
41
# File 'lib/steam/request.rb', line 39

def env
  super.merge(headers)
end

#headersObject



102
103
104
# File 'lib/steam/request.rb', line 102

def headers
  @headers ||= {}
end

#headers=(headers) ⇒ Object



98
99
100
# File 'lib/steam/request.rb', line 98

def headers=(headers)
  self.headers.merge!(headers)
end

#host=(host) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/steam/request.rb', line 70

def host=(host)
  host, self.port = host.split(':')
  @env.merge!(
    'HTTP_HOST'      => host,
    'rack.test.host' => host
  )
end

#input=(input) ⇒ Object



106
107
108
109
110
111
# File 'lib/steam/request.rb', line 106

def input=(input)
  @env.merge!(
    'rack.input'     => input.is_a?(String) ? StringIO.new(input) : input,
    'CONTENT_LENGTH' => input.length.to_s
  )
end

#path=(path) ⇒ Object



92
93
94
95
96
# File 'lib/steam/request.rb', line 92

def path=(path)
  @env.merge!(
    'PATH_INFO' => path && !path.empty? ? path : '/'
  )
end

#port=(port) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/steam/request.rb', line 78

def port=(port)
  port ||= protocol == 'https' ? 443 : 80
  @env.merge!(
    'SERVER_PORT'    => port,
    'rack.test.port' => port
  )
end

#query=(query) ⇒ Object



86
87
88
89
90
# File 'lib/steam/request.rb', line 86

def query=(query)
  @env.merge!(
    'QUERY_STRING' => query.to_s
  )
end

#scheme=(scheme) ⇒ Object Also known as: protocol=



60
61
62
63
64
65
66
# File 'lib/steam/request.rb', line 60

def scheme=(scheme)
  @env.merge!(
    'rack.url_scheme'  => scheme,
    'rack.test.scheme' => scheme
  )
  self.port = nil # reset the port so we switch according to the protocol
end

#update(options = {}) ⇒ Object



35
36
37
# File 'lib/steam/request.rb', line 35

def update(options = {})
  options.each { |name, value| send("#{name}=", value) }
end

#url=(url) ⇒ Object Also known as: uri=



43
44
45
46
47
48
49
50
# File 'lib/steam/request.rb', line 43

def url=(url)
  url = URI.parse(url)
  self.path   = url.path
  self.scheme = url.scheme if url.scheme
  self.host   = url.host   if url.host
  self.port   = url.port   if url.port
  self.query  = url.query  if url.query
end