Sha256: 1719a2028325a06da52bf5a824c4b464a955b6cb52b944c61a9a07f214157355
Contents?: true
Size: 581 Bytes
Versions: 3
Compression:
Stored size: 581 Bytes
Contents
# frozen_string_literal: true module SafeRequestTimeout # Rack middleware that adds a timeout block to all requests. class RackMiddleware # @param app [Object] The Rack application to wrap. # @param timeout [Integer, Proc, nil] The timeout in seconds. def initialize(app, timeout = nil) @app = app @timeout = timeout @timeout_block = true if timeout.is_a?(Proc) && timeout.arity == 1 end def call(env) SafeRequestTimeout.timeout(@timeout_block ? @timeout.call(env) : @timeout) do @app.call(env) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems