Class: Waves::Request
Overview
Waves::Request represents an HTTP request and has methods for accessing anything relating to the request. See Rack::Request for more information, since many methods are actually delegated to Rack::Request.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- METHODS =
Supported request methods
%w{get post put delete head options trace}
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#content_type ⇒ Object
The request content type.
-
#domain ⇒ Object
The request domain.
-
#initialize(env) ⇒ Request
constructor
Create a new request.
-
#method ⇒ Object
The request method.
-
#method_missing(name, *args) ⇒ Object
Accessor not explicitly defined by Waves::Request are delegated to Rack::Request.
-
#not_found ⇒ Object
Raise a not found exception.
-
#path ⇒ Object
The request path (PATH_INFO).
-
#redirect(path, status = '302') ⇒ Object
Issue a redirect for the given path.
Constructor Details
#initialize(env) ⇒ Request
Create a new request. Takes a env parameter representing the request passed in from Rack. You shouldn’t need to call this directly.
13 14 15 16 17 |
# File 'lib/runtime/request.rb', line 13 def initialize( env ) @request = Rack::Request.new( env ) @response = Waves::Response.new( self ) @session = Waves::Session.new( self ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
Accessor not explicitly defined by Waves::Request are delegated to Rack::Request. Check the Rack documentation for more information.
21 22 23 |
# File 'lib/runtime/request.rb', line 21 def method_missing(name,*args) @request.send(name,*args) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
9 10 11 |
# File 'lib/runtime/request.rb', line 9 def response @response end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
9 10 11 |
# File 'lib/runtime/request.rb', line 9 def session @session end |
Instance Method Details
#content_type ⇒ Object
The request content type.
36 37 38 |
# File 'lib/runtime/request.rb', line 36 def content_type @request.env['CONTENT_TYPE'] end |
#domain ⇒ Object
The request domain. Ex: www.fubar.com
31 32 33 |
# File 'lib/runtime/request.rb', line 31 def domain @request.host end |
#method ⇒ Object
The request method. Because browsers can’t send PUT or DELETE requests this can be simulated by sending a POST with a hidden field named ‘_method’ and a value with ‘PUT’ or ‘DELETE’. Also accepted is when a query parameter named ‘_method’ is provided.
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/runtime/request.rb', line 52 def method @method ||= begin request_method = @request.request_method.downcase if request_method == 'post' _method = @request['_method'] _method.downcase! if _method METHODS.include?(_method) ? _method.intern : :post else request_method.intern end end end |
#not_found ⇒ Object
Raise a not found exception.
66 67 68 |
# File 'lib/runtime/request.rb', line 66 def not_found raise Waves::Dispatchers::NotFoundError.new( @request.url + ' not found.' ) end |
#path ⇒ Object
The request path (PATH_INFO). Ex: /entry/2008-01-17
26 27 28 |
# File 'lib/runtime/request.rb', line 26 def path @request.path_info end |
#redirect(path, status = '302') ⇒ Object
Issue a redirect for the given path.
71 72 73 |
# File 'lib/runtime/request.rb', line 71 def redirect( path, status = '302' ) raise Waves::Dispatchers::Redirect.new( path, status ) end |