From c60e3e3276de1b0bd55c77110b5bf00a411bf9a0 Mon Sep 17 00:00:00 2001 From: Bart de Water <118401830+bdewater-thatch@users.noreply.github.com> Date: Thu, 16 Oct 2025 12:43:43 -0400 Subject: [PATCH] Inherit Request class from ActionDispatch if available --- lib/rack/attack/request.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/rack/attack/request.rb b/lib/rack/attack/request.rb index 1cac479d..43de43d1 100644 --- a/lib/rack/attack/request.rb +++ b/lib/rack/attack/request.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -# Rack::Attack::Request is the same as ::Rack::Request by default. +# Rack::Attack::Request is the same as :ActionDispatch::Request in Rails apps, +# and ::Rack::Request in other apps by default. # # This is a safe place to add custom helper methods to the request object # through monkey patching: @@ -15,7 +16,7 @@ # module Rack class Attack - class Request < ::Rack::Request + class Request < defined?(::ActionDispatch::Request) ? ::ActionDispatch::Request : ::Rack::Request end end end