| | 124 | # Returns the lowercase name of the HTTP server software. |
|---|
| | 125 | def server_software |
|---|
| | 126 | (@env['SERVER_SOFTWARE'] && /^([a-zA-Z]+)/ =~ @env['SERVER_SOFTWARE']) ? $1.downcase : nil |
|---|
| | 127 | end |
|---|
| | 128 | |
|---|
| | 129 | |
|---|
| | 130 | # Returns the complete URL used for this request |
|---|
| | 131 | def url |
|---|
| | 132 | request.protocol + request.host_with_port + request.request_uri |
|---|
| | 133 | end |
|---|
| | 134 | |
|---|
| | 135 | # Return 'https://' if this is an SSL request and 'http://' otherwise. |
|---|
| | 136 | def protocol |
|---|
| | 137 | ssl? ? 'https://' : 'http://' |
|---|
| | 138 | end |
|---|
| | 139 | |
|---|
| | 140 | # Is this an SSL request? |
|---|
| | 141 | def ssl? |
|---|
| | 142 | @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' |
|---|
| | 143 | end |
|---|
| | 144 | |
|---|
| | 145 | # Returns the host for this request, such as example.com. |
|---|
| | 146 | def host |
|---|
| | 147 | end |
|---|
| | 148 | |
|---|
| | 149 | # Returns a host:port string for this request, such as example.com or |
|---|
| | 150 | # example.com:8080. |
|---|
| | 151 | def host_with_port |
|---|
| | 152 | host + port_string |
|---|
| | 153 | end |
|---|
| | 154 | |
|---|
| | 155 | # Returns the port number of this request as an integer. |
|---|
| | 156 | def port |
|---|
| | 157 | @port_as_int ||= @env['SERVER_PORT'].to_i |
|---|
| | 158 | end |
|---|
| | 159 | |
|---|
| | 160 | # Returns the standard port number for this request's protocol |
|---|
| | 161 | def standard_port |
|---|
| | 162 | case protocol |
|---|
| | 163 | when 'https://' then 443 |
|---|
| | 164 | else 80 |
|---|
| | 165 | end |
|---|
| | 166 | end |
|---|
| | 167 | |
|---|
| | 168 | # Returns a port suffix like ":8080" if the port number of this request |
|---|
| | 169 | # is not the default HTTP port 80 or HTTPS port 443. |
|---|
| | 170 | def port_string |
|---|
| | 171 | (port == standard_port) ? '' : ":#{port}" |
|---|
| | 172 | end |
|---|
| | 173 | |
|---|
| 205 | | # Returns the port number of this request as an integer. |
|---|
| 206 | | def port |
|---|
| 207 | | @port_as_int ||= @env['SERVER_PORT'].to_i |
|---|
| 208 | | end |
|---|
| 209 | | |
|---|
| 210 | | # Returns the standard port number for this request's protocol |
|---|
| 211 | | def standard_port |
|---|
| 212 | | case protocol |
|---|
| 213 | | when 'https://' then 443 |
|---|
| 214 | | else 80 |
|---|
| 215 | | end |
|---|
| 216 | | end |
|---|
| 217 | | |
|---|
| 218 | | # Returns a port suffix like ":8080" if the port number of this request |
|---|
| 219 | | # is not the default HTTP port 80 or HTTPS port 443. |
|---|
| 220 | | def port_string |
|---|
| 221 | | (port == standard_port) ? '' : ":#{port}" |
|---|
| 222 | | end |
|---|
| 223 | | |
|---|
| 224 | | # Returns a host:port string for this request, such as example.com or |
|---|
| 225 | | # example.com:8080. |
|---|
| 226 | | def host_with_port |
|---|
| 227 | | host + port_string |
|---|
| | 233 | |
|---|
| | 234 | # Receive the raw post data. |
|---|
| | 235 | # This is useful for services such as REST, XMLRPC and SOAP |
|---|
| | 236 | # which communicate over HTTP POST but don't use the traditional parameter format. |
|---|
| | 237 | def raw_post |
|---|
| | 238 | @env['RAW_POST_DATA'] |
|---|
| | 239 | end |
|---|
| | 240 | |
|---|
| | 241 | # Returns both GET and POST parameters in a single hash. |
|---|
| | 242 | def parameters |
|---|
| | 243 | @parameters ||= request_parameters.update(query_parameters).update(path_parameters).with_indifferent_access |
|---|