Class: SignalWire::AgentBase::AgentBodyLimitMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/signalwire/agent/agent_base.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, max_size) ⇒ AgentBodyLimitMiddleware

Returns a new instance of AgentBodyLimitMiddleware.



2081
2082
2083
2084
# File 'lib/signalwire/agent/agent_base.rb', line 2081

def initialize(app, max_size)
  @app      = app
  @max_size = max_size
end

Instance Method Details

#call(env) ⇒ Object



2086
2087
2088
2089
2090
2091
2092
# File 'lib/signalwire/agent/agent_base.rb', line 2086

def call(env)
  if env['CONTENT_LENGTH'] && env['CONTENT_LENGTH'].to_i > @max_size
    body = JSON.generate({ 'error' => 'Request body too large' })
    return [413, { 'content-type' => 'application/json' }, [body]]
  end
  @app.call(env)
end