Socket
Socket
Sign inDemoInstall

method-override

Package Overview
Dependencies
Maintainers
6
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

method-override - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

6

History.md

@@ -0,1 +1,7 @@

1.0.2 / 2014-05-22
==================
* Handle `req.body` key referencing array or object
* Handle multiple HTTP headers
1.0.1 / 2014-05-17

@@ -2,0 +8,0 @@ ==================

28

index.js

@@ -29,5 +29,7 @@ /*!

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

@@ -37,13 +39,21 @@

if (req.body && typeof req.body === 'object' && key in req.body) {
method = req.body[key].toLowerCase();
delete req.body[key];
method = req.body[key]
delete req.body[key]
}
// check X-HTTP-Method-Override
if (req.headers['x-http-method-override']) {
method = req.headers['x-http-method-override'].toLowerCase();
val = req.headers['x-http-method-override']
if (val) {
// multiple headers get joined with comma by node.js core
method = val.split(/ *, */)
}
if (Array.isArray(method)) {
method = method[0]
}
// replace
if (supports(method)) req.method = method.toUpperCase();
if (supports(method)) {
req.method = method.toUpperCase()
}

@@ -59,3 +69,5 @@ next();

function supports(method) {
return ~methods.indexOf(method);
return method
&& typeof method === 'string'
&& methods.indexOf(method.toLowerCase()) !== -1
}
{
"name": "method-override",
"description": "Override HTTP verbs",
"version": "1.0.1",
"version": "1.0.2",
"author": {

@@ -11,2 +11,8 @@ "name": "Jonathan Ong",

},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",

@@ -25,3 +31,4 @@ "repository": {

"devDependencies": {
"mocha": "~1.18.2",
"istanbul": "0.2.10",
"mocha": "~1.19.0",
"supertest": "~0.12.1"

@@ -33,4 +40,6 @@ },

"scripts": {
"test": "mocha --reporter spec"
"test": "mocha --reporter dot test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec test/"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc