Append a middleware in function of its nature and the filter value stored in req.__connectSequenceFilterValue
@function
@inner
@private
@param {Function} middleware
@returns {undefined}
357845
function appendOnFilterValue (middleware) {
  if (isErrorHandler(middleware)) {
    this.append(function (err, req, res, next) {
      if (req.__connectSequenceFilterValue) {
        middleware(err, req, res, next)
      } else {
        next()
      }
    })
  } else {
    this.append(function (req, res, next) {
      if (req.__connectSequenceFilterValue) {
        middleware(req, res, next)
      } else {
        next()
      }
    })
  }
}
718695
function requestFilter() {
  return function(req, res, next) {
    if (!_isJsonRequest(req) && !_isVoidFilterRoute(req)) {
      return _renderAppShell(res);
    }
    next();
  };
}
1093056
function compose(middleware){
	return function *(next){
		var i = middleware.length;
		next = next || function *(){};
		var mw;

		while (i--) {
			mw = middleware[i];
			next = mw.call(this, next);
		}

		yield *next;
	}
}
1359147
function middleware(req, res, next) {
		//Check to see if req.url matches a fingerprinted URL
		var info = fingerprints[req.originalUrl];
		//If this request matches a fingerprint
		if(info)
		{
			//Set headers
			if(info.lastModified)
				res.setHeader("Last-Modified", info.lastModified.toUTCString() );
			if(info.etag)
				res.setHeader("ETag", info.etag);
			if(info.expires)
			{
				res.setHeader("Expires", info.expires.toUTCString() );
				res.setHeader("Cache-Control", "public; max-age=" +
					Math.floor((info.expires.getTime() - new Date().getTime() ) / 1000) );
			}
			//Check If-Modified-Since and If-None-Match headers and return 304, if appropriate
			if((req.headers["if-none-match"] && info.etag == req.headers["if-none-match"]) ||
				(req.headers["if-modified-since"] && info.lastModified.toUTCString() ==
					req.headers["if-modified-since"]) )
				return (res.sendStatus || res.send).call(res, 304);
		}
		//If req.assetFingerprint is already there, do nothing.
		if(!req.assetFingerprint)
		{
			//Create req.assetFingerprint
			req.assetFingerprint = assetFingerprint;
			//Expose req.assetFingerprint in Express helper
			res.locals.assetFingerprint = function() {
				return assetFingerprint.apply(req, arguments);
			};
		}
		//Run next middleware
		next();
	}
830170
function middleware(schema, options = optionsDefault) {
    return (req, res, next) => {
        // Test if schema exists
        /* istanbul ignore if */
        if (!schema) {
            next();
        }

        // Test if Joi is provided
        const Joi = options.joi || require('joi');

        // Object to validate
        const objectToValidate = {};
        ['params', 'body', 'query', 'headers'].forEach((key) => {
            if (schema[key]) {
                objectToValidate[key] = req[key];
            }
        });

        // Get joi options
        const joiOptions = options.joiOptions || {};

        // Get callback
        const callback = options.validationCallback || validationCallback;

        return Joi.validate(objectToValidate, schema, joiOptions, callback(req, res, next, options));
    };
}
971543
function createDefaultMiddleware(connect, options) {
					var middlewares = [];

					var directory = options.directory || options.base;
					// Serve static files.
					middlewares.push(serveStatic(options.base));
					// Make directory browse-able.
					middlewares.push(serveIndex(directory));
					return middlewares;
				}
376875
function Middleware(...middleware) {
    return (ctr) => {
        if (middleware != undefined) {
            let c = exports.globalKCState.getOrInsertController(ctr);
            c.middleware = middleware.concat(c.middleware);
        }
    };
}
907701
function runMiddlewareStack(stack, req, res, callback) {
  let index = 0;
  // the middleware layer handover callback
  function next(err) {
    // get next middleware callback from stack
    const handle = stack[index++];
    // if no more layers in stack, invoke done callback and exit recursion
    if (!handle) {
      callback(err);
      return;
    }
    let error = err;
    // call the middleware handler
    try {
      if (err && handle.length === 4) {
        // there is an error and it's an error-handling middleware
        handle(err, req, res, next);
        return;
      } else if (!err && handle.length < 4) {
        // no error and it's a request-handling middleware
        handle(req, res, next);
        return;
      }
    } catch (e) {
      // if new error thrown, replace the error
      error = e;
    }
    // otherwise skip layer
    next(error);
  }
  // start going through middleware stack
  next();
}
1199517
function(middlewares, response, callback) {
        var that = this;
        var middleware = middlewares.shift();
        if (!middleware) {
            return callback(null, response);
        }
        var middleware_callback = function(retVal) {
            /**
             * got an error
             * break middleware chain and callback
             */
            if (retVal && retVal instanceof Error) {
                return callback(retVal, response);
            }
            /**
             * got a response object
             * break middleware chain and bypass request
             */
            if (retVal && typeof retVal == 'object') {
                return callback(null, retVal);
            }
            that._callResponseMiddlewares(middlewares, response, callback);
        };
        try {
            middleware(response, middleware_callback);
        } catch (e) {
            callback(e, response);
        }
    }
1355740
public function addMiddleware($middleware, $priority = PriorityQueue::NORMAL)
    {
        if (is_array($middleware) && isset($middleware['priority'])) {
            $priority = $middleware['priority'];
        }

        $this->getMiddlewares()->insert($middleware, $priority);

        return $this;
    }
700569
function wrap(fn) {
  // Error handling middleware
  if (fn.length === 4) {
    return async function wrappedErrorHandler(error, req, res, next) {
      next = _once(next);
      try {
        await fn(error, req, res, next);
        res.headersSent ? null : next();
      } catch(err) {
        res.headersSent ? null : next(err);
      }
    };
  }

  return async function wrappedMiddleware(req, res, next) {
    next = _once(next);
    try {
      await fn(req, res, next);
      res.headersSent ? null : next();
    } catch(err) {
      res.headersSent ? null : next(err);
    }
  };
}
155280
function (routes) {
		var self = this;

	
		fs.readdirSync(this.middlewareBasePath()).filter(file => file.match(/\.js$/) || file.match(/\.coffee$/)).forEach(function (file) {
			var middlewareName = file.replace(/\.js$/, '').replace(/\.coffee$/, '');
			self.middlewares[middlewareName] = require(path.join(self.middlewareBasePath(), middlewareName));
		});


		for (var root in routes) {
			if (root && routes[root]) {
				for(var key in routes[root]) {
					var method = key.trim().split(' ')[0].toLowerCase();
					var routerMiddelware = routes[root][key];
					var endpoint;

					if (root == 'index') endpoint = ((key.trim().split(' ')[1].toLowerCase() != '/') ? key.trim().split(' ')[1].toLowerCase() : '/');
					else endpoint = '/' + root + ((key.trim().split(' ')[1].toLowerCase() != '/') ? key.trim().split(' ')[1].toLowerCase() : '');

					self.__endpoint__handler(method, endpoint, routerMiddelware);
				}
			}
		}
	}
152418
function (key) {
    // Assume the middleware is a function
    var middleware = key;

    // If the middleware is a string
    if (typeof middleware === 'string') {
      // Look it up and assert it was found
      middleware = MIDDLEWARES[key];
      assert(middleware, 'value-mapper middleware "' + key + '" could not be found."');
    }

    // Add the middleware to our stack
    this.middlewares.push(middleware);
  }
1197256
def use(middleware, *args, &block)
      return if faraday.builder.locked?
      faraday.builder.insert_before(Middleware::ParseJson, middleware, *args, &block)
    end
609838
function (routerMiddelware, req, res, next) {
		var middlewareFilename = routerMiddelware.split('.')[0];
		var middlewareFunction = routerMiddelware.split('.')[1];

		if (!req.pipa) req.pipa = {};

		this.middlewares[middlewareFilename][middlewareFunction](req, res, function (data) {
			_.extend(req.pipa, data); next();
		});
	}
345357
function compose () {
  // the function required by the server
  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)
        }
      }
    })()
  }

  middlewareF.stack = []
  middlewareF.options = compose.options || {}

  ;[].slice.call(arguments).forEach(function (a) {
    middlewareF.stack = middlewareF.stack.concat(compose.decompose(a))
  })

  // extends
  ;[ 'before', 'after', 'replace', 'remove', 'push', 'unshift', 'clone' ].forEach(function (p) {
    middlewareF[p] = compose[p]
  })

  // inject stats middleware
  if (compose.options.stats) {
    middlewareF.options = {}
    middlewareF.options.stats = compose.options.stats
  }

  return middlewareF
}
1126144
function compose(middlewares, ctx) {
    let i = middlewares.length;
    let next = async function(){};

    // 循环算出来next
    for (let i = middlewares.length - 1; i >=0; i--) {
        next = getCallback(middlewares[i], ctx, next);
    }

    return next;
}