如何重新配置​​ Rails 默认中间件

How to reconfigure Rails default middleware

Rails 附带了一系列默认包含的中间件。但是,如果我想将参数传递给中间件怎么办?例如,ActionDispatch::RemoteIp 有两个可选参数:ip_spoofing_check and custom_proxies。如何重新配置​​已包含的 ActionDispatch::RemoteIp 中间件,但为 custom_proxies 传递我自己的值?

ActionDispatch::RemoteIp checks for IP spoofing attacks and gets valid client_ip from request headers. Configurable with the config.action_dispatch.ip_spoofing_check, and config.action_dispatch.trusted_proxies options.
- Rails Guides - Configuring Middleware

事实上,大多数中间件都有设置器,因此您可以重新配置它,而不必更改初始化参数。