diff --git a/actionpack/lib/action_dispatch/middleware/request_id.rb b/actionpack/lib/action_dispatch/middleware/request_id.rb index 85f95ad111..d7a1a0710c 100644 --- a/actionpack/lib/action_dispatch/middleware/request_id.rb +++ b/actionpack/lib/action_dispatch/middleware/request_id.rb @@ -15,9 +15,9 @@ module ActionDispatch # The unique request id can be used to trace a request end-to-end and would typically end up being part of log files # from multiple pieces of the stack. class RequestId - def initialize(app, header: nil) + def initialize(app, header:) @app = app - @header = header || "X-Request-Id" + @header = header end def call(env) diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb index 99a4116a82..fa87ca7344 100644 --- a/actionpack/lib/action_dispatch/railtie.rb +++ b/actionpack/lib/action_dispatch/railtie.rb @@ -23,6 +23,7 @@ module ActionDispatch config.action_dispatch.use_authenticated_cookie_encryption = false config.action_dispatch.use_cookies_with_metadata = false config.action_dispatch.perform_deep_munge = true + config.action_dispatch.request_id_header = "X-Request-Id" config.action_dispatch.default_headers = { "X-Frame-Options" => "SAMEORIGIN", diff --git a/actionpack/test/dispatch/request_id_test.rb b/actionpack/test/dispatch/request_id_test.rb index da701a4a9f..b4578540e9 100644 --- a/actionpack/test/dispatch/request_id_test.rb +++ b/actionpack/test/dispatch/request_id_test.rb @@ -33,7 +33,7 @@ class RequestIdTest < ActiveSupport::TestCase end private - def stub_request(env = {}, header: nil) + def stub_request(env = {}, header: "X-Request-Id") ActionDispatch::RequestId.new(lambda { |environment| [ 200, environment, [] ] }, header: header).call(env) ActionDispatch::Request.new(env) end @@ -68,7 +68,7 @@ class RequestIdResponseTest < ActionDispatch::IntegrationTest end private - def with_test_route_set(header: nil) + def with_test_route_set(header: "X-Request-Id") with_routing do |set| set.draw do get "/", to: ::RequestIdResponseTest::TestController.action(:index)