Class: Dispatcher::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/dispatcher.rb

Overview

A HTTP request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*vals) ⇒ Request

Generates a new request.

Any values passed will be set to the appropriate attributes.



101
102
103
104
105
106
107
108
109
# File 'lib/dispatcher.rb', line 101

def initialize(*vals)
  @headers = HTTPHeaderHash.new
  @env     = Hash.new
  @values  = Hash.new
  
  vals.each do |key, value|
    instance_variable_set(key, value)
  end
end

Instance Attribute Details

#bodyObject

The body of the request, if given.



90
91
92
# File 'lib/dispatcher.rb', line 90

def body
  @body
end

#envObject

Every environment variable passed from the server



96
97
98
# File 'lib/dispatcher.rb', line 96

def env
  @env
end

#headersObject

Any HTTP headers passed along with the request



87
88
89
# File 'lib/dispatcher.rb', line 87

def headers
  @headers
end

#valuesObject

A full set of CGI environment values



93
94
95
# File 'lib/dispatcher.rb', line 93

def values
  @values
end

Instance Method Details

#methodObject

The current request method.



112
113
114
# File 'lib/dispatcher.rb', line 112

def method
  @values['REQUEST_METHOD']
end

#pathObject

The requested path



117
118
119
# File 'lib/dispatcher.rb', line 117

def path
  @values['PATH_INFO']
end

#uriObject Also known as: url

The fully qualified URI of the request



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/dispatcher.rb', line 122

def uri
  # protocol
  result = 'http'
  if @values['HTTPS'] == 'on'
    result += 's'
  end
  
  # server/port
  result += "://#{@values['HTTP_HOST']}"
  
  # path
  result += @values['PATH_INFO']
  
  # query
  if @values['QUERY_STRING'] != ''
    result += "?#{@values['QUERY_STRING']}"
  end
  
  return result
end