Disable middleware at runtime
6368
function(middleware) {
        this.middlewares = this.middlewares.filter(function(element) {
            if (element.fun === middleware)
                return false;
            return true;
        });
    }
168120
def disable(resource_group_name, workflow_name, custom_headers:nil)
      response = disable_async(resource_group_name, workflow_name, custom_headers:custom_headers).value!
      nil
    end
437373
def use(self, *middleware: MiddlewareType) -> None:
        
        for m in middleware:
            if is_middleware(m):
                self.middleware.append(m)
512727
def add_middleware(self, middleware):
        """"""
        if self.middleware is None:
            self._middleware = []
        self.middleware.append(middleware)
296133
public function withoutMiddleware($middleware = null)
    {
        if (is_null($middleware)) {
            $this->app->instance('middleware.disable', true);

            return $this;
        }

        foreach ((array) $middleware as $abstract) {
            $this->app->instance($abstract, new class {
                public function handle($request, $next)
                {
                    return $next($request);
                }
            });
        }

        return $this;
    }
101286
function sanitize (fn) {
  return function (/* path, ...middleware */) {
    var middleware = []
    var startindex = 0
    var endindex = arguments.length
    var path
    var options

    if (typeof arguments[0] === 'string') {
      path = arguments[0]
      startindex = 1
    }

    if (typeof arguments[arguments.length - 1] === 'object') {
      endindex = arguments.length - 1
      options = arguments[endindex]
    }

    // Concat all the middleware functions.
    for (var i = startindex; i < endindex; i++) {
      middleware.push(arguments[i])
    }

    middleware = flatten(middleware)

    if (middleware.length === 0) {
      throw new TypeError('Expected a function but got no arguments')
    }

    if (middleware.length === 1) {
      middleware = middleware[0]
    } else {
      middleware = compose(middleware)
    }

    fn.call(this, path, middleware, extend({}, this._options, options))

    return this
  }
}
468981
function createDefaultMiddleware(connect, options) {
    var middlewares = [];
    if (!Array.isArray(options.base)) {
      options.base = [options.base];
    }
    // Options for serve-static module. See https://www.npmjs.com/package/serve-static
    var defaultStaticOptions = {};
    var directory = options.directory || options.base[options.base.length - 1];
    options.base.forEach(function(base) {
      // Serve static files.
      var path = base.path || base;
      var staticOptions = base.options || defaultStaticOptions;
      middlewares.push(serveStatic(path, staticOptions));
    });
    // Make directory browse-able.
    middlewares.push(serveIndex(directory.path || directory, directory.options));
    return middlewares;
  }
677989
function Stack (middleware, context) {
  var handle = function (args, next) { next.call(context) }
  middleware.reverse().forEach(function (layer) {
    var child = handle
    handle = function (args, next) {
      layer(args, function () {
        child(args, next)
      })
    }
  })
  return handle
}
1029008
function toHaveMiddleware(middleware) {
    
    expect(this.actual).toExist('Route is undefined');
    toBeAnExpressRoute(this.actual.route);
    expect(this.actual.route.stack.length).toBeGreaterThan(1, 'No middleware found');
    if(expressGuards.isMiddleware(middleware)) {
        expect(this.actual.route.stack.find(l => l.handle.toString() === middleware.toString())).toExist(`middleware is not defined`);
    } else {
        const name = middleware || '<anonymous>';
        expect(this.actual.route.stack.find(l => l.name === name)).toExist(`${name} is not defined`);
    }
}
958089
function ActionMiddleware(...middleware) {
    return function (target, propertyKey, descriptor) {
        if (middleware != undefined) {
            let m = exports.globalKCState.getOrInsertController(target.constructor).getOrInsertMethod(propertyKey);
            m.middleware = middleware.concat(m.middleware);
        }
    };
}
945773
function use(events, middleware)
{
  // if no middleware supplied assume it's single argument call
  if (!middleware)
  {
    middleware = events;
    events     = null;
  }

  // make it uniform
  events = normalizeEvents(events);

  // store middleware per event
  events.forEach(function(e)
  {
    // bind middleware to the current context
    (this._stack[e] = this._stack[e] || []).push(middleware.bind(this));

    // make mark in history
    this.logger.debug({message: 'Added middleware to the stack', event: e, middleware: middleware});
  }.bind(this));
}
1064778
def use_default_middleware
      use Serf::Middleware::RequestTimer
      use Serf::Middleware::ParcelMasher
      use Serf::Middleware::UuidTagger
      use Serf::Middleware::ErrorHandler
    end
773737
function onlyFunctions(middleware) {
  if (!middleware || !Array.isArray(middleware)) {
    return [];
  }

  return middleware.filter(function (fn) {
    return typeof fn === 'function';
  });
}
474320
function middleware(req, res, next) {
  req.security.csrf.exclude = true;
  next();
}
186691
function middlewareF (req, res, end) {
    var index = 0

    // inject stats middleware
    if (middlewareF.options && middlewareF.options.stats) {
      middlewareF.stack = middlewareF.stack.map(function (mw) {
        var fn
        if (typeof mw === 'object') {
          var key = Object.keys(mw)[0]
          if (!mw[key].stats) {
            fn = {}
            fn[key] = middlewareF.options.stats(mw[key])
          }
        } else {
          if (!mw.stats) {
            fn = middlewareF.options.stats(mw)
          }
        }
        return fn
      })
    }

    // looping over all middleware functions defined by stack
    ;(function next (err) {
      var arity
      var middleware = middlewareF.stack[index++] // obtain the current middleware from the stack

      if (!middleware) {
        // we are at the end of the stack
        end && end(err)
        return
      } else {
        // extract middleware from object
        if (typeof (middleware) === 'object') {
          var name = Object.keys(middleware)[0]
          if (typeof (middleware[name]) === 'function') {
            middleware = middleware[name]
          } else {
            middleware = function (req, res, next) {
              next(new Error('missing middleware'))
            }
          }
        }

        try {
          arity = middleware.length // number of arguments function middleware requires
          // handle errors
          if (err) {
            // If the middleware function contains 4 arguments than this will act as an "error trap"
            if (arity === 4) {
              middleware(err, req, res, function (err) {
                nextTick(next, err)
              })
            } else {
              // otherwise check the next middleware
              next(err)
            }
          } else if (arity < 4) {
            // process non "error trap" stack
            middleware(req, res, function (err) {
              nextTick(next, err)
            })
          } else {
            // loop over "error traps" if no error `err` is set.
            next()
          }
        } catch (e) {
          next(e)
        }
      }
    })()
  }
1103714
def disable_precompute(panel):
  """"""
  task_id = panel['data_source']['precompute']['task_id']
  result = scheduler_client.cancel(task_id)
  if result['status'] != 'success':
    raise RuntimeError(result.get('reason'))
47298
private void handle(final Request request, final Response response, final List<Middleware> middlewares) throws Exception {
		if (middlewares.isEmpty()) {
			throw new NotFoundException();
		}
		
		Middleware current = middlewares.remove(0);
		current.handle(request, response, new MiddlewareChain() {
			@Override
			public void next() throws Exception {
				// recursive call
				handle(request, response, middlewares);
			}
		});
	}