Class: Whoosh::Middleware::RequestLimit
- Inherits:
-
Object
- Object
- Whoosh::Middleware::RequestLimit
- Defined in:
- lib/whoosh/middleware/request_limit.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, max_bytes: 1_048_576) ⇒ RequestLimit
constructor
1MB default.
Constructor Details
#initialize(app, max_bytes: 1_048_576) ⇒ RequestLimit
1MB default
8 9 10 11 |
# File 'lib/whoosh/middleware/request_limit.rb', line 8 def initialize(app, max_bytes: 1_048_576) # 1MB default @app = app @max_bytes = max_bytes end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/whoosh/middleware/request_limit.rb', line 13 def call(env) content_length = env["CONTENT_LENGTH"]&.to_i || 0 if content_length > @max_bytes return [ 413, { "content-type" => "application/json" }, [JSON.generate({ error: "request_too_large", max_bytes: @max_bytes })] ] end @app.call(env) end |