Search code examples
ruby-on-railsrubyrack

How to reconfigure Rails default middleware


Rails comes with a range of middleware which is included by default. But what if I want to pass arguments to the middleware? For example, ActionDispatch::RemoteIp takes two optional arguments: ip_spoofing_check and custom_proxies. How do I reconfigure the already included ActionDispatch::RemoteIp middleware but passing in my own value for custom_proxies?


Solution

  • 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

    In fact most of the middleware has setters so that you can reconfigure it instead of having to change the initialization arguments.