Class: Dispatcher::Request
- Inherits:
-
Object
- Object
- Dispatcher::Request
- Defined in:
- lib/dispatcher.rb
Overview
A HTTP request.
Instance Attribute Summary collapse
-
#body ⇒ Object
The body of the request, if given.
-
#env ⇒ Object
Every environment variable passed from the server.
-
#headers ⇒ Object
Any HTTP headers passed along with the request.
-
#values ⇒ Object
A full set of CGI environment values.
Instance Method Summary collapse
-
#initialize(*vals) ⇒ Request
constructor
Generates a new request.
-
#method ⇒ Object
The current request method.
-
#path ⇒ Object
The requested path.
-
#uri ⇒ Object
(also: #url)
The fully qualified URI of the request.
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
#body ⇒ Object
The body of the request, if given.
90 91 92 |
# File 'lib/dispatcher.rb', line 90 def body @body end |
#env ⇒ Object
Every environment variable passed from the server
96 97 98 |
# File 'lib/dispatcher.rb', line 96 def env @env end |
#headers ⇒ Object
Any HTTP headers passed along with the request
87 88 89 |
# File 'lib/dispatcher.rb', line 87 def headers @headers end |
#values ⇒ Object
A full set of CGI environment values
93 94 95 |
# File 'lib/dispatcher.rb', line 93 def values @values end |
Instance Method Details
#method ⇒ Object
The current request method.
112 113 114 |
# File 'lib/dispatcher.rb', line 112 def method @values['REQUEST_METHOD'] end |
#path ⇒ Object
The requested path
117 118 119 |
# File 'lib/dispatcher.rb', line 117 def path @values['PATH_INFO'] end |
#uri ⇒ Object 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 |