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
Modules: Utilities Classes: ParseError, Query
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#traits ⇒ Object
readonly
Returns the value of attribute traits.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#accept ⇒ Object
Requested representation MIME type.
-
#accept_charset ⇒ Object
Requested charset(s).
-
#accept_language ⇒ Object
Requested language(s).
- #basename ⇒ Object
-
#extension ⇒ Object
(also: #ext)
File extension of path, with leading dot.
- #if_modified_since ⇒ Object
-
#initialize(env) ⇒ Request
constructor
Create a new request.
-
#method ⇒ Object
The request method.
-
#path ⇒ Object
The request path (PATH_INFO).
-
#query ⇒ Object
(also: #params)
Access to “params” - aka the query string - as a hash.
-
#rack_request ⇒ Object
Rack request object.
-
#requested ⇒ Object
Combination of Accept and file extension for matching.
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.
17 18 19 20 21 |
# File 'lib/waves/request/request.rb', line 17 def initialize(env) @traits = Class.new { include Attributes }.new( :waves => {} ) @request = Rack::Request.new(env).freeze @response = Waves::Response.new( self ) end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
12 13 14 |
# File 'lib/waves/request/request.rb', line 12 def response @response end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
12 13 14 |
# File 'lib/waves/request/request.rb', line 12 def session @session end |
#traits ⇒ Object (readonly)
Returns the value of attribute traits.
12 13 14 |
# File 'lib/waves/request/request.rb', line 12 def traits @traits end |
Instance Method Details
#[](key) ⇒ Object
46 |
# File 'lib/waves/request/request.rb', line 46 def []( key ) ; @request.env[ key.to_s ] ; end |
#accept ⇒ Object
Requested representation MIME type
71 72 73 |
# File 'lib/waves/request/request.rb', line 71 def accept() @accept ||= Accept.parse(@request.env['HTTP_ACCEPT']) end |
#accept_charset ⇒ Object
Requested charset(s).
100 101 102 |
# File 'lib/waves/request/request.rb', line 100 def accept_charset() @charset ||= Accept.parse(@request.env['HTTP_ACCEPT_CHARSET']) end |
#accept_language ⇒ Object
Requested language(s).
108 109 110 |
# File 'lib/waves/request/request.rb', line 108 def accept_language() @lang ||= Accept.parse(@request.env['HTTP_ACCEPT_LANGUAGE']) end |
#basename ⇒ Object
119 120 121 |
# File 'lib/waves/request/request.rb', line 119 def basename @basename ||= File.basename( path ) end |
#extension ⇒ Object Also known as: ext
File extension of path, with leading dot
113 114 115 |
# File 'lib/waves/request/request.rb', line 113 def extension @ext ||= ( ( e = File.extname( path ) ).empty? ? nil : e ) end |
#if_modified_since ⇒ Object
40 41 42 43 44 |
# File 'lib/waves/request/request.rb', line 40 def if_modified_since @if_modified_since ||= ( Time.parse( @request.env[ 'HTTP_IF_MODIFIED_SINCE' ] ) if @request.env.has_key?( 'HTTP_IF_MODIFIED_SINCE' ) ) 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.
65 66 67 68 |
# File 'lib/waves/request/request.rb', line 65 def method @method ||= ( ( ( m = @request.request_method.downcase ) == 'post' and ( n = @request['_method'] ) ) ? n.downcase : m ).intern end |
#path ⇒ Object
The request path (PATH_INFO). Ex: /entry/2008-01-17
49 |
# File 'lib/waves/request/request.rb', line 49 def path ; @request.path_info ; end |
#query ⇒ Object Also known as: params
Access to “params” - aka the query string - as a hash
52 |
# File 'lib/waves/request/request.rb', line 52 def query ; @request.params ; end |
#rack_request ⇒ Object
Rack request object.
25 26 27 |
# File 'lib/waves/request/request.rb', line 25 def rack_request() @request end |
#requested ⇒ Object
Combination of Accept and file extension for matching.
A file extension takes precedence over the Accept header, the Accept is ignored.
The absence of a file extension is indicated using the special MIME type MimeTypes::Unspecified, which allows specialised handling thereof. The resource must specifically accept Unspecified for it to have an effect.
92 93 94 |
# File 'lib/waves/request/request.rb', line 92 def requested() @requested ||= ( extension ? Accept.new( Accept.parse( MimeTypes[ extension ].join(",") ) + accept ).uniq : accept ) end |