Class: ActionController::AbstractRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/request.rb

Overview

These methods are available in both the production and test Request objects.

Direct Known Subclasses

CgiRequest, TestRequest

Instance Method Summary collapse

Instance Method Details

#cookiesObject



98
99
# File 'lib/action_controller/request.rb', line 98

def cookies
end

#delete?Boolean

Returns:

  • (Boolean)


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

def delete?
  method == :delete
end

#envObject



92
93
# File 'lib/action_controller/request.rb', line 92

def env
end

#get?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/action_controller/request.rb', line 13

def get?
  method == :get
end

#head?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/action_controller/request.rb', line 29

def head?
  method == :head
end

#hostObject



95
96
# File 'lib/action_controller/request.rb', line 95

def host
end

#host_with_portObject



73
74
75
76
77
78
79
80
81
# File 'lib/action_controller/request.rb', line 73

def host_with_port
  if env['HTTP_HOST']
    env['HTTP_HOST']
  elsif (protocol == "http://" && port == 80) || (protocol == "https://" && port == 443)
    host
  else
    host + ":#{port}"
  end
end

#methodObject



9
10
11
# File 'lib/action_controller/request.rb', line 9

def method
  env['REQUEST_METHOD'].downcase.intern
end

#parametersObject

Returns both GET and POST parameters in a single hash.



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

def parameters
  @parameters ||= request_parameters.update(query_parameters)
end

#pathObject



65
66
67
# File 'lib/action_controller/request.rb', line 65

def path
  request_uri ? request_uri.split("?").first : ""
end

#portObject



69
70
71
# File 'lib/action_controller/request.rb', line 69

def port
  env["SERVER_PORT"].to_i
end

#post?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/action_controller/request.rb', line 17

def post?
  method == :post
end

#protocolObject



57
58
59
# File 'lib/action_controller/request.rb', line 57

def protocol
  port == 443 ? "https://" : "http://"
end

#put?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/action_controller/request.rb', line 21

def put?
  method == :put
end

#query_parametersObject

– Must be implemented in the concrete request ++



86
87
# File 'lib/action_controller/request.rb', line 86

def query_parameters
end

#remote_ipObject

Determine originating IP address. REMOTE_ADDR is the standard but will fail if the user is behind a proxy. HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these before falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma- delimited list in the case of multiple chained proxies; the first is the originating IP.



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/action_controller/request.rb', line 39

def remote_ip
  return env['HTTP_CLIENT_IP'] if env.include? 'HTTP_CLIENT_IP'

  if env.include? 'HTTP_X_FORWARDED_FOR' then
    remote_ips = env['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip|
        ip =~ /^unknown$|^(10|172\.16|192\.168)\./i
    end

    return remote_ips.first.strip unless remote_ips.empty?
  end

  return env['REMOTE_ADDR']
end

#request_parametersObject



89
90
# File 'lib/action_controller/request.rb', line 89

def request_parameters
end

#request_uriObject



53
54
55
# File 'lib/action_controller/request.rb', line 53

def request_uri
  env["REQUEST_URI"]
end

#reset_sessionObject



104
105
# File 'lib/action_controller/request.rb', line 104

def reset_session
end

#sessionObject



101
102
# File 'lib/action_controller/request.rb', line 101

def session
end

#ssl?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/action_controller/request.rb', line 61

def ssl?
  protocol == "https://"
end