diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index da7feb75ac..ed9ac6922e 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -431,6 +431,10 @@ module ActionDispatch super || scheme == "wss" end + def inspect # :nodoc: + "#<#{self.class.name} #{method} #{original_url.dump} for #{remote_ip}>" + end + private def check_method(name) HTTP_METHOD_LOOKUP[name] || raise(ActionController::UnknownHttpMethod, "#{name}, accepted HTTP methods are #{HTTP_METHODS[0...-1].join(', ')}, and #{HTTP_METHODS[-1]}") diff --git a/actionpack/test/dispatch/request_test.rb b/actionpack/test/dispatch/request_test.rb index d725e171c4..e0ee910227 100644 --- a/actionpack/test/dispatch/request_test.rb +++ b/actionpack/test/dispatch/request_test.rb @@ -1290,3 +1290,17 @@ class EarlyHintsRequestTest < BaseRequestTest assert_equal expected_hints, early_hints end end + +class RequestInspectTest < BaseRequestTest + test "inspect" do + request = stub_request( + "REQUEST_METHOD" => "POST", + "REMOTE_ADDR" => "1.2.3.4", + "HTTP_X_FORWARDED_PROTO" => "https", + "HTTP_X_FORWARDED_HOST" => "example.com:443", + "PATH_INFO" => "/path/", + "QUERY_STRING" => "q=1" + ) + assert_match %r(#), request.inspect + end +end