Check Content-Length in ResponseWithLimitAdapter (#31285)
This commit is contained in:
parent
103e544cfa
commit
9d0cafd06b
4 changed files with 107 additions and 9 deletions
|
@ -234,13 +234,17 @@ class Request
|
|||
end
|
||||
|
||||
def body_with_limit(limit = 1.megabyte)
|
||||
raise Mastodon::LengthValidationError if content_length.present? && content_length > limit
|
||||
require_limit_not_exceeded!(limit)
|
||||
|
||||
contents = truncated_body(limit)
|
||||
raise Mastodon::LengthValidationError if contents.bytesize > limit
|
||||
raise Mastodon::LengthValidationError, "Body size exceeds limit of #{limit}" if contents.bytesize > limit
|
||||
|
||||
contents
|
||||
end
|
||||
|
||||
def require_limit_not_exceeded!(limit)
|
||||
raise Mastodon::LengthValidationError, "Content-Length #{content_length} exceeds limit of #{limit}" if content_length.present? && content_length > limit
|
||||
end
|
||||
end
|
||||
|
||||
if ::HTTP::Response.methods.include?(:body_with_limit) && !Rails.env.production?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue