class Elastomer::Middleware::LimitSize

Request middleware that raises an exception if the request body exceeds a `max_request_size`.

Attributes

max_request_size[R]

Public Class Methods

new(app = nil, options = {}) click to toggle source
Calls superclass method
# File lib/elastomer/middleware/limit_size.rb, line 8
def initialize(app = nil, options = {})
  super(app)
  @max_request_size = options.fetch(:max_request_size)
end

Public Instance Methods

call(env) click to toggle source
# File lib/elastomer/middleware/limit_size.rb, line 15
def call(env)
  if body = env[:body]
    if body.is_a?(String) && body.bytesize > max_request_size
      raise ::Elastomer::Client::RequestSizeError,
        "Request of size `#{body.bytesize}` exceeds the maximum requst size: #{max_request_size}"
    end
  end
  @app.call(env)
end