Skip to content

Commit

Permalink
Minor logic DRY up
Browse files Browse the repository at this point in the history
  • Loading branch information
shayonj committed Dec 26, 2022
1 parent dc2b6ee commit dead2b4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/puma/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ def try_to_parse_proxy_protocol
end

def try_to_finish
if env[CONTENT_LENGTH] && @http_content_length_limit
@http_content_length_limit_exceeded = env[CONTENT_LENGTH].to_i > @http_content_length_limit
if env[CONTENT_LENGTH] && above_http_content_limit(env[CONTENT_LENGTH].to_i)
@http_content_length_limit_exceeded = true
end

if @http_content_length_limit_exceeded
Expand Down Expand Up @@ -254,7 +254,7 @@ def try_to_finish

@parsed_bytes = @parser.execute(@env, @buffer, @parsed_bytes)

if @parser.finished? && @http_content_length_limit && (@parser.body.bytesize > @http_content_length_limit)
if @parser.finished? && above_http_content_limit(@parser.body.bytesize)
@http_content_length_limit_exceeded = true
end

Expand Down Expand Up @@ -613,5 +613,9 @@ def set_ready
@requests_served += 1
@ready = true
end

def above_http_content_limit(value)
@http_content_length_limit&.< value
end
end
end

0 comments on commit dead2b4

Please sign in to comment.