Skip to content

Commit 0e29a82

Browse files
authored
Refactor for better readability (#4529)
Move to method to get user_id
1 parent 45eeac6 commit 0e29a82

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

middleware/base_rate_limiter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def call(env)
103103
rate_limit_headers = RateLimitHeaders.new(@header_suffix)
104104

105105
if apply_rate_limiting?(env)
106-
user_guid = user_token?(env) ? env['cf.user_guid'] : client_ip(ActionDispatch::Request.new(env))
106+
user_guid = get_user_id(env)
107107

108108
count, expires_in = @expiring_request_counter.increment(user_guid, @reset_interval, @logger)
109109

@@ -118,6 +118,10 @@ def call(env)
118118
[status, headers.merge(rate_limit_headers.to_hash), body]
119119
end
120120

121+
def get_user_id(env)
122+
user_token?(env) ? env['cf.user_guid'] : client_ip(ActionDispatch::Request.new(env))
123+
end
124+
121125
private
122126

123127
def apply_rate_limiting?(_env)

0 commit comments

Comments
 (0)