Class: Innate::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Innate::Request
- Defined in:
- /home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb
Overview
Subclass Rack::Request and add some convenient methods.
An instance is available via the #request method in your Node.
NOTE: Please make sure to read the documentation of Rack::Request together with this, as there are a lot of features available.
A list of methods from Rack::Request so you get a gist of it:
Generally
- body
- cookies
- env
- fullpath
- host
- port
- scheme
- url
ENV shortcuts
- accept_encoding
- content_charset
- content_length
- content_type
- ip
- media_type
- media_type_params
- path_info
- path_info=
- query_string
- referrer
- script_name
- script_name=
- xhr?
Query request method
- delete?
- get?
- head?
- post?
- put?
- request_method
parameter handling
- []
- []=
- form_data?
- params
- values_at
Direct Known Subclasses
Constant Summary
- LOCAL =
(ipv4 + ipv6).map{|range| IPAddr.new(range)}
Class Method Summary (collapse)
-
+ (Object) current
Currently handled request from Thread.current[:request] Call it from anywhere via Innate::Request.current.
Instance Method Summary (collapse)
-
- (Object) [](value, *keys)
Let's allow #[] to act like #values_at.
-
- (URI) domain(path = nil, options = {})
Try to figure out the domain we are running on, this might work for some deployments but fail for others, given the combination of servers in front.
-
- (Boolean) local_net?(address = ip)
Request is from a local network? Checks both IPv4 and IPv6 Answer is true if the IP address making the request is from local network.
-
- (Object) request_uri
the full request URI provided by Rack::Request e.g.
-
- (Object) subset(*keys)
Answers with a subset of request.params with only the key/value pairs for which you pass the keys.
Class Method Details
+ (Object) current
Currently handled request from Thread.current[:request] Call it from anywhere via Innate::Request.current
61 62 63 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 61 def self.current Current.request end |
Instance Method Details
- (Object) [](value, *keys)
Let's allow #[] to act like #values_at.
Usage given a GET request like /hey?foo=duh&bar=doh
request[:foo, :bar] # => ['duh', 'doh']
Both +value+ and the elements of +keys+ will be turned into String by #to_s.
72 73 74 75 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 72 def [](value, *keys) return super(value) if keys.empty? [value, *keys].map{|key| super(key) } end |
- (URI) domain(path = nil, options = {})
Try to figure out the domain we are running on, this might work for some deployments but fail for others, given the combination of servers in front.
118 119 120 121 122 123 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 118 def domain(path = nil, = {}) uri = URI(self.url) uri.path = path.to_s if path uri.query = nil unless [:keep_query] uri end |
- (Boolean) local_net?(address = ip)
Request is from a local network? Checks both IPv4 and IPv6 Answer is true if the IP address making the request is from local network. Optional argument address can be used to check any IP address.
134 135 136 137 138 139 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 134 def local_net?(address = ip) addr = IPAddr.new(address) LOCAL.find{|range| range.include?(addr) } rescue ArgumentError => ex raise ArgumentError, ex unless ex. == 'invalid address' end |
- (Object) request_uri
the full request URI provided by Rack::Request e.g. "http://localhost:7000/controller/action?foo=bar.xhtml"
79 80 81 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 79 def request_uri env['REQUEST_URI'] || env['PATH_INFO'] end |
- (Object) subset(*keys)
Answers with a subset of request.params with only the key/value pairs for which you pass the keys. Valid keys are objects that respond to :to_s
96 97 98 99 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/request.rb', line 96 def subset(*keys) keys = keys.map{|key| key.to_s } params.reject{|key, value| not keys.include?(key) } end |