lib/framework/middleware.js
function header(ctx) {
  var prefix = describe(ctx);
  var schema = transform.parameters(ctx.operation.spec, 'header');

  if (!schema) {
    debug(prefix + 'header middleware disabled (no schema)');
    return;
  }

  var env = ctx.operation.resource.api.env;
  var options = validateOptions(ctx.operation, 'header', true);

  // Create a list of headers to split on comma
  var allowMultiple = {};
  ctx.operation.spec.parameters.forEach(function(parameter) {
    if (parameter.paramType === 'header' && parameter.allowMultiple) {
      var name = parameter.name.toLowerCase();
      allowMultiple[name] = constants.singleHeaders.indexOf(name) < 0;
    }
  });

  schema = {
    type: 'object',
    properties: { header: schema },
    required: ['header'],
  };

  return function(req, res, next) {
    var header = lodash.cloneDeep(req.headers);

    // This only works for small subset of headers before Node v0.11
    lodash.forOwn(header, function(value, name) {
      if (allowMultiple[name]) header[name] = value.split(', ');
    });

    if (validate(res, env.validate(schema, { header: header }, options))) {
      req.sf.header = header;
      next();
    }
  };
}
function header(ctx) {
  var prefix = describe(ctx);
  var schema = transform.parameters(ctx.operation.spec, 'header');

  if (!schema) {
    debug(prefix + 'header middleware disabled (no schema)');
    return;
  }

  var env = ctx.operation.resource.api.env;
  var options = validateOptions(ctx.operation, 'header', true);

  // Create a list of headers to split on comma
  var allowMultiple = {};
  ctx.operation.spec.parameters.forEach(function(parameter) {
    if (parameter.paramType === 'header' && parameter.allowMultiple) {
      var name = parameter.name.toLowerCase();
      allowMultiple[name] = constants.singleHeaders.indexOf(name) < 0;
    }
  });

  schema = {
    type: 'object',
    properties: { header: schema },
    required: ['header'],
  };

  return function(req, res, next) {
    var header = lodash.cloneDeep(req.headers);

    // This only works for small subset of headers before Node v0.11
    lodash.forOwn(header, function(value, name) {
      if (allowMultiple[name]) header[name] = value.split(', ');
    });

    if (validate(res, env.validate(schema, { header: header }, options))) {
      req.sf.header = header;
      next();
    }
  };
}
function header ( ctx ) { var prefix = describe ( ctx ) ; var schema = transform . parameters ( ctx . operation . spec , 'header' ) ; if ( ! schema ) { debug ( prefix + 'header middleware disabled (no schema)' ) ; return ; } var env = ctx . operation . resource . api . env ; var options = validateOptions ( ctx . operation , 'header' , true ) ; // Create a list of headers to split on comma var allowMultiple = { } ; ctx . operation . spec . parameters . forEach ( function ( parameter ) { if ( parameter . paramType === 'header' && parameter . allowMultiple ) { var name = parameter . name . toLowerCase ( ) ; allowMultiple [ name ] = constants . singleHeaders . indexOf ( name ) < 0 ; } } ) ; schema = { type : 'object' , properties : { header : schema } , required : [ 'header' ] , } ; return function ( req , res , next ) { var header = lodash . cloneDeep ( req . headers ) ; // This only works for small subset of headers before Node v0.11 lodash . forOwn ( header , function ( value , name ) { if ( allowMultiple [ name ] ) header [ name ] = value . split ( ', ' ) ; } ) ; if ( validate ( res , env . validate ( schema , { header : header } , options ) ) ) { req . sf . header = header ; next ( ) ; } } ; }
Validate headers based on Swagger spec.
Validate headers based on Swagger spec .