diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2004-11-24 01:04:44 +0000 |
commit | db045dbbf60b53dbe013ef25554fd013baf88134 (patch) | |
tree | 257830e3c76458c8ff3d1329de83f32b23926028 /actionpack/lib/action_controller/request.rb | |
download | rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.gz rails-db045dbbf60b53dbe013ef25554fd013baf88134.tar.bz2 rails-db045dbbf60b53dbe013ef25554fd013baf88134.zip |
Initial
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/request.rb')
-rwxr-xr-x | actionpack/lib/action_controller/request.rb | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb new file mode 100755 index 0000000000..1085066ea0 --- /dev/null +++ b/actionpack/lib/action_controller/request.rb @@ -0,0 +1,99 @@ +module ActionController + # These methods are available in both the production and test Request objects. + class AbstractRequest + # Returns both GET and POST parameters in a single hash. + def parameters + @parameters ||= request_parameters.update(query_parameters) + end + + def method + env['REQUEST_METHOD'].downcase.intern + end + + def get? + method == :get + end + + def post? + method == :post + end + + def put? + method == :put + end + + def delete? + method == :delete + end + + # 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. + def remote_ip + if env['HTTP_CLIENT_IP'] + env['HTTP_CLIENT_IP'] + elsif env['HTTP_X_FORWARDED_FOR'] + remote_ip = env['HTTP_X_FORWARDED_FOR'].split(',').reject { |ip| + ip =~ /^unknown$|^(10|172\.16|192\.168)\./i + }.first + + remote_ip ? remote_ip.strip : env['REMOTE_ADDR'] + else + env['REMOTE_ADDR'] + end + end + + def request_uri + env["REQUEST_URI"] + end + + def protocol + port == 443 ? "https://" : "http://" + end + + def path + request_uri ? request_uri.split("?").first : "" + end + + def port + env["SERVER_PORT"].to_i + end + + 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 + + #-- + # Must be implemented in the concrete request + #++ + def query_parameters + end + + def request_parameters + end + + def env + end + + def host + end + + def cookies + end + + def session + end + + def reset_session + end + end +end |