Class: Gin::Request

Inherits:
Rack::Request
  • Object
show all
Includes:
Constants
Defined in:
lib/gin/request.rb

Constant Summary

Constants included from Constants

Constants::ASYNC_CALLBACK, Constants::CACHE_CTRL, Constants::CNT_DISPOSITION, Constants::CNT_LENGTH, Constants::CNT_TYPE, Constants::ENV_DEV, Constants::ENV_PROD, Constants::ENV_STAGE, Constants::ENV_TEST, Constants::EPOCH, Constants::ETAG, Constants::EXPIRES, Constants::FWD_FOR, Constants::FWD_HOST, Constants::GIN_ACTION, Constants::GIN_CTRL, Constants::GIN_ERRORS, Constants::GIN_PATH_PARAMS, Constants::GIN_RELOADED, Constants::GIN_ROUTE, Constants::GIN_STACK, Constants::GIN_STATIC, Constants::GIN_TEMPLATES, Constants::GIN_TIMESTAMP, Constants::HTTP_VERSION, Constants::IF_MATCH, Constants::IF_MOD_SINCE, Constants::IF_NONE_MATCH, Constants::IF_UNMOD_SINCE, Constants::LAST_MOD, Constants::LOCATION, Constants::PATH_INFO, Constants::PRAGMA, Constants::QUERY_STRING, Constants::REMOTE_ADDR, Constants::REMOTE_USER, Constants::REQ_METHOD, Constants::SESSION_SECRET

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



4
5
6
7
# File 'lib/gin/request.rb', line 4

def initialize env
  super
  self.params.update env[GIN_PATH_PARAMS] if env[GIN_PATH_PARAMS]
end

Instance Method Details

#forwarded?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/gin/request.rb', line 10

def forwarded?
  @env.include? FWD_HOST
end

#idempotent?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gin/request.rb', line 25

def idempotent?
  safe? or put? or delete?
end

#ipObject Also known as: remote_ip



35
36
37
38
39
40
41
# File 'lib/gin/request.rb', line 35

def ip
  if addr = @env['HTTP_X_FORWARDED_FOR']
    (addr.split(',').grep(/\d\./).first || @env['REMOTE_ADDR']).to_s.strip
  else
    @env['REMOTE_ADDR']
  end
end

#paramsObject



30
31
32
# File 'lib/gin/request.rb', line 30

def params
  @params ||= process_params(super) || {}
end

#safe?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gin/request.rb', line 20

def safe?
  get? or head? or options? or trace?
end

#ssl?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/gin/request.rb', line 15

def ssl?
  scheme == 'https'
end