Sha256: c5ef05d57eeeb750f962a039322b2a8fe327eac5facfacdd5fea3c25b86f103b

Contents?: true

Size: 1.14 KB

Versions: 26

Compression:

Stored size: 1.14 KB

Contents

/*!
 * Ext JS Connect
 * Copyright(c) 2010 Sencha Inc.
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var queryString = require('querystring');

/**
 * Valid http methods.
 *
 * @type Array
 */

var methods = ['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'OPTIONS'];

/**
 * Pass an optional `key` to use when checking for
 * a method override, othewise defaults to __method_.
 *
 * @param {String} key
 * @return {Function}
 * @api public
 */

module.exports = function methodOverride(key){
    key = key || "_method";
    return function methodOverride(req, res, next) {
        var method = req.method;

        // Check req.body (bodyDecoder)
        if (typeof req.body === 'object' && key in req.body) {
            method = req.body[key];
            delete req.body[key];
        // Check X-HTTP-Method-Override
        } else if (req.headers['x-http-method-override']) {
            method = req.headers['x-http-method-override'];
        }

        // Ensure method is valid, and normalize
        method = method.toUpperCase();
        if (methods.indexOf(method) >= 0) {
            req.method = method;
        }
        
        next();
    };
};

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
vulcan-0.8.2 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.8.1 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.8.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.7.2 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.7.1 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.7.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.6.1 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.6.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.5.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.4.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.3.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.5 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.4 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.3 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.2 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.1 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.2.0 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.1.6 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.1.5 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js
vulcan-0.1.4 server/node_modules/connect-form/support/connect/lib/connect/middleware/methodOverride.js