| Class | Waves::Request |
| In: |
lib/runtime/request.rb
|
| Parent: | Object |
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.
| host | -> | domain |
| response | [R] | |
| session | [R] | |
| traits | [R] |
Create a new request. Takes a env parameter representing the request passed in from Rack. You shouldn‘t need to call this directly.
# File lib/runtime/request.rb, line 16
16: def initialize( env )
17: @traits = Class.new { include Attributes }.new( :waves => {} )
18: @request = Rack::Request.new( env ).freeze
19: @response = Waves::Response.new( self )
20: @session = Waves::Session.new( self )
21: end
this is a hack - need to incorporate browser variations for "accept" here … def accept ; Accept.parse(@request.env[‘HTTP_ACCEPT’]).unshift( Waves.config.mime_types[ path ] ).compact.uniq ; end
# File lib/runtime/request.rb, line 103
103: def accept ; @accept ||= Accept.parse( Waves.config.mime_types[ path.downcase ] || 'text/html' ) ; end
# File lib/runtime/request.rb, line 104
104: def accept_charset ; @charset ||= Accept.parse(@request.env['HTTP_ACCEPT_CHARSET']) ; end
# File lib/runtime/request.rb, line 105
105: def accept_language ; @lang ||= Accept.parse(@request.env['HTTP_ACCEPT_LANGUAGE']) ; end
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.
# File lib/runtime/request.rb, line 47
47: def method
48: @method ||= ( ( ( m = @request.request_method.downcase ) == 'post' and
49: ( n = @request['_method'] ) ) ? n.downcase : m ).intern
50: end
access HTTP headers as methods
# File lib/runtime/request.rb, line 55
55: def method_missing( name, *args, &body )
56: return super unless args.empty? and body.nil?
57: key = "HTTP_#{name.to_s.upcase}"
58: @request.env[ key ] if @request.env.has_key?( key )
59: end
Raise a not found exception.
# File lib/runtime/request.rb, line 62
62: def not_found
63: raise Waves::Dispatchers::NotFoundError, "#{@request.url} not found."
64: end