aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Claghorn <george.claghorn@gmail.com>2018-07-31 14:06:47 -0400
committerGitHub <noreply@github.com>2018-07-31 14:06:47 -0400
commite2aaf5c237717296858240b02d4d2f1ade740458 (patch)
tree5a61c36e1527cd1c2c519fc1c2dfe3dcb7ed5120
parent0f5497499cee78c52b14485d102c602884fb20cb (diff)
parent7e40e9585a5596558d71f76c61bb35316cb17a53 (diff)
downloadrails-e2aaf5c237717296858240b02d4d2f1ade740458.tar.gz
rails-e2aaf5c237717296858240b02d4d2f1ade740458.tar.bz2
rails-e2aaf5c237717296858240b02d4d2f1ade740458.zip
Merge pull request #33489 from Atul9/remote-ip
Log the remote IP addr of clients behind a proxy
-rw-r--r--railties/lib/rails/rack/logger.rb2
-rw-r--r--railties/test/application/rack/logger_test.rb6
2 files changed, 7 insertions, 1 deletions
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb
index 4ea7e40319..3a95b55811 100644
--- a/railties/lib/rails/rack/logger.rb
+++ b/railties/lib/rails/rack/logger.rb
@@ -50,7 +50,7 @@ module Rails
'Started %s "%s" for %s at %s' % [
request.request_method,
request.filtered_path,
- request.ip,
+ request.remote_ip,
Time.now.to_default_s ]
end
diff --git a/railties/test/application/rack/logger_test.rb b/railties/test/application/rack/logger_test.rb
index d949a48366..ea425d5fa5 100644
--- a/railties/test/application/rack/logger_test.rb
+++ b/railties/test/application/rack/logger_test.rb
@@ -53,6 +53,12 @@ module ApplicationTests
wait
assert_match 'Started HEAD "/"', logs
end
+
+ test "logger logs correct remote IP address" do
+ get "/", {}, { "REMOTE_ADDR" => "127.0.0.1", "HTTP_X_FORWARDED_FOR" => "1.2.3.4" }
+ wait
+ assert_match 'Started GET "/" for 1.2.3.4', logs
+ end
end
end
end