class Request::Rack

Rack request

Constants

CONTENT_LENGTH
CONTENT_LENGTH_REGEXP
IF_MODIFIED_SINCE
InvalidKeyError

Error raised when an invalid rack env key is accessed

RACK_URL_SCHEME
REQUEST_METHOD
SERVER_PORT

Attributes

rack_env[R]

Return rack env

@return [Hash]

@api private

Public Class Methods

new(rack_env) click to toggle source

Initialize object

@param [Hash] rack_env

@return [undefined]

@api private

# File lib/request/rack.rb, line 22
def initialize(rack_env)
  @rack_env = rack_env
end

Private Class Methods

accessor(name, key, *args) click to toggle source

Declare accessor

@param [Symbol] name @param [Key] key

@return [undefined]

@api private

# File lib/request/rack.rb, line 43
def self.accessor(name, key, *args)
  define_method(name) do
    access(key, *args)
  end
end

Public Instance Methods

content_length() click to toggle source

Return content length

@return [Fixnum]

@api private

# File lib/request/rack.rb, line 91
def content_length
  value = @rack_env.fetch(CONTENT_LENGTH) do
    return 0
  end

  unless value =~ CONTENT_LENGTH_REGEXP
    raise InvalidKeyError, 'invalid content length'
  end

  value.to_i
end
if_modified_since() click to toggle source

Return if modified since

@return [Time]

if present

@return [nil]

otherwise

@api private

# File lib/request/rack.rb, line 125
def if_modified_since
  value = @rack_env.fetch(IF_MODIFIED_SINCE) { return }
  begin
    Time.httpdate(value) 
  rescue ArgumentError 
    nil
  end
end
port() click to toggle source

Return http port

@return [Fixnum]

@api private

# File lib/request/rack.rb, line 56
def port
  @rack_env.fetch(SERVER_PORT).to_i(10)
end
protocol() click to toggle source

Return request protocol

@return [Protocol]

@api private

# File lib/request/rack.rb, line 67
def protocol
  Protocol.get(access(RACK_URL_SCHEME))
end
query_params() click to toggle source

Return query params

@return [Array]

@api private

# File lib/request/rack.rb, line 110
def query_params
  Addressable::URI.form_unencode(query_string)
end
request_method() click to toggle source

Return request method

@return [Method]

@api private

# File lib/request/rack.rb, line 78
def request_method
  Method.get(access(REQUEST_METHOD))
end

Private Instance Methods

access(key, *args) click to toggle source

Return value for key

@param [Key] key

@return [Object]

@api private

# File lib/request/rack.rb, line 151
def access(key, *args)
  @rack_env.fetch(key, *args)
end