Class: Waves::Request
Overview
Waves::Request represents an HTTP request and provides convenient methods for accessing request attributes. See Rack::Request for documentation of any method not defined here.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- METHODS =
Supported request methods
%w{get post put delete head options trace}
Instance Attribute Summary collapse
-
#blackboard ⇒ Object
readonly
Returns the value of attribute blackboard.
-
#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).
- #rack_request ⇒ Object
-
#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.
11 12 13 14 15 16 |
# File 'lib/runtime/request.rb', line 11 def initialize( env ) @request = Rack::Request.new( env ) @response = Waves::Response.new( self ) @session = Waves::Session.new( self ) @blackboard = Waves::Blackboard.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.
22 23 24 |
# File 'lib/runtime/request.rb', line 22 def method_missing(name,*args) @request.send(name,*args) end |
Instance Attribute Details
#blackboard ⇒ Object (readonly)
Returns the value of attribute blackboard.
7 8 9 |
# File 'lib/runtime/request.rb', line 7 def blackboard @blackboard end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/runtime/request.rb', line 7 def response @response end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
7 8 9 |
# File 'lib/runtime/request.rb', line 7 def session @session end |
Instance Method Details
#content_type ⇒ Object
The request content type.
37 38 39 |
# File 'lib/runtime/request.rb', line 37 def content_type @request.env['CONTENT_TYPE'] end |
#domain ⇒ Object
The request domain. Ex: www.fubar.com
32 33 34 |
# File 'lib/runtime/request.rb', line 32 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.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/runtime/request.rb', line 53 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.
67 68 69 |
# File 'lib/runtime/request.rb', line 67 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
27 28 29 |
# File 'lib/runtime/request.rb', line 27 def path @request.path_info end |
#rack_request ⇒ Object
18 |
# File 'lib/runtime/request.rb', line 18 def rack_request; @request; end |
#redirect(path, status = '302') ⇒ Object
Issue a redirect for the given path.
72 73 74 |
# File 'lib/runtime/request.rb', line 72 def redirect( path, status = '302' ) raise Waves::Dispatchers::Redirect.new( path, status ) end |