diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c7d7733..842bdd4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -32,7 +32,7 @@ class ApplicationController < ActionController::Base end def client_remote_ip - @client_remote_ip ||= request.env["HTTP_X_FORWARDED_FOR"] + @client_remote_ip ||= Settings.uses_proxy ? request.remote_ip : request.ip end def check_honeypot diff --git a/config/settings.sample.yml b/config/settings.sample.yml index 7f4f670..882aa01 100644 --- a/config/settings.sample.yml +++ b/config/settings.sample.yml @@ -1,6 +1,9 @@ # framework secret_key_base: 0ce1f02a4b3fc4d1a1c8d22973b21e8589e9314dc338294953f0b985e3f44f12c8af74f2d9ba6f7c7bdb736c4efc5ea3f8135e23b1a036d033cd23331383ac75 +# deployment +uses_proxy: true + # application default_ttl: 3600 min_ttl: 60 diff --git a/spec/controllers/users/records_controller_spec.rb b/spec/controllers/users/records_controller_spec.rb index ed62ef1..6bbbe40 100644 --- a/spec/controllers/users/records_controller_spec.rb +++ b/spec/controllers/users/records_controller_spec.rb @@ -21,7 +21,7 @@ describe Users::RecordsController do it "modifies @record with remote IP" do ip = '127.0.0.3' - request.env["HTTP_X_FORWARDED_FOR"] = ip + @request.env['REMOTE_ADDR'] = ip get :modify, :authentication_token => a_record.authentication_token response.should be_success response.body.should == Users::RecordsController::MODIFY_OK @@ -31,7 +31,7 @@ describe Users::RecordsController do it "errors when not A type @record with" do ip = '127.0.0.3' - request.env["HTTP_X_FORWARDED_FOR"] = ip + @request.env['REMOTE_ADDR'] = ip get :modify, :authentication_token => soa_record.authentication_token response.should be_success response.body.should == Users::RecordsController::MODIFY_ERROR