Class: Innate::Request

### Home Classes Methods

### In Files

- lib/innate/request.rb

### Parent

Rack::Request

### Methods

- ::current
- #[]
- #domain
- #local_net?
- #request_uri
- #subset

### Class/Module Index

Quicksearch

- Innate
- Innate::Action
- Innate::Adapter
- Innate::Cache
- Innate::Cache::API
- Innate::Cache::DRb
- Innate::Cache::FileBased
- Innate::Cache::Marshal
- Innate::Cache::Memory
- Innate::Cache::YAML
- Innate::Current
- Innate::Etanni
- Innate::Helper
- Innate::Helper::Aspect
- Innate::Helper::Aspect::SingletonMethods
- Innate::Helper::CGI
- Innate::Helper::Flash
- Innate::Helper::Link
- Innate::Helper::Redirect
- Innate::Helper::Render
- Innate::HelperAccess
- Innate::HelpersHelper
- Innate::LRUHash
- Innate::LogHub
- Innate::Mock
- Innate::Mock::Session
- Innate::Node
- Innate::Optioned
- Innate::Optioned::SingletonMethods
- Innate::Options
- Innate::Request
- Innate::Response
- Innate::Rewrite
- Innate::Route
- Innate::Session
- Innate::Session::Flash
- Innate::SingletonMethods
- Innate::StateAccessor
- Innate::Traited
- Innate::Trinity
- Innate::URLMap
- Innate::View
- Innate::View::ERB
- Innate::View::Etanni
- Innate::View::None
- Logger
- Logger::ColorFormatter
- Object

No matching classes.

# Innate::Request

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

### Constants

LOCAL

### Public Class Methods

current() click to toggle source

Currently handled request from Thread.current Call it from anywhere via Innate::Request.current

    # File lib/innate/request.rb, line 61
    def self.current
      Current.request
    end

### Public Instance Methods

[](value, *keys) click to toggle source

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.

    # File lib/innate/request.rb, line 72
    def [](value, *keys)
      return super(value) if keys.empty?
      [value, *keys].map{|key| super(key) }
    end

domain(path = nil, options = {}) click to toggle source

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.

@example usage

    domain
    # => #<URI::HTTPS:0xb769ecb0 URL:https://localhost:7000/>
    domain('/foo')
    # => #<URI::HTTPS:0xb769ecb0 URL:https://localhost:7000/foo>

@param [to_s] path

@return [URI]

@api external @author manveru

    # File lib/innate/request.rb, line 118
    def domain(path = nil, options = {})
      uri = URI(self.url)
      uri.path = path.to_s if path
      uri.query = nil unless options[:keep_query]
      uri
    end

local_net?(address = ip) click to toggle source

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.

    # File 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.message == 'invalid address'
    end

request_uri() click to toggle source

the full request URI provided by Rack::Request e.g. "localhost:7000/controller/action?foo=bar.xhtml"

    # File lib/innate/request.rb, line 79
    def request_uri
      env['REQUEST_URI'] || env['PATH_INFO']
    end

subset(*keys) click to toggle source

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

@example usage

    request.params
    # => {'name' => 'jason', 'age' => '45', 'job' => 'lumberjack'}
    request.subset('name')
    # => {'name' => 'jason'}
    request.subset(:name, :job)
    # => {'name' => 'jason', 'job' => 'lumberjack'}

    # File 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.