-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e6d87e8
Showing
8 changed files
with
238 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store* | ||
ehthumbs.db | ||
Icon? | ||
Thumbs.db | ||
|
||
# Node.js # | ||
########### | ||
lib-cov | ||
*.seed | ||
*.log | ||
*.csv | ||
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
results | ||
|
||
node_modules | ||
npm-debug.log | ||
|
||
# Git # | ||
####### | ||
*.orig | ||
*.BASE.* | ||
*.BACKUP.* | ||
*.LOCAL.* | ||
*.REMOTE.* | ||
|
||
# Components # | ||
############## | ||
|
||
/build | ||
/components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_js: | ||
- "0.10" | ||
- "0.11" | ||
language: node_js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
test: | ||
@NODE_ENV=test ./node_modules/.bin/mocha \ | ||
--reporter spec \ | ||
--require should | ||
|
||
.PHONY: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Method Override | ||
|
||
Previously `connect.methodOverride()`. | ||
|
||
Usage: | ||
|
||
```js | ||
var app = require('connect'); | ||
app.use(require('body-parser')()); | ||
app.use(require('method-override')()) | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Jonathan Ong [email protected] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/*! | ||
* Connect - methodOverride | ||
* Copyright(c) 2010 Sencha Inc. | ||
* Copyright(c) 2011 TJ Holowaychuk | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* Module dependencies. | ||
*/ | ||
|
||
var methods = require('methods'); | ||
|
||
/** | ||
* Method Override: | ||
* | ||
* Provides faux HTTP method support. | ||
* | ||
* Pass an optional `key` to use when checking for | ||
* a method override, otherwise defaults to _\_method_. | ||
* The original method is available via `req.originalMethod`. | ||
* | ||
* @param {String} key | ||
* @return {Function} | ||
* @api public | ||
*/ | ||
|
||
module.exports = function methodOverride(key){ | ||
key = key || "_method"; | ||
return function methodOverride(req, res, next) { | ||
var method; | ||
req.originalMethod = req.originalMethod || req.method; | ||
|
||
// req.body | ||
if (req.body && typeof req.body === 'object' && key in req.body) { | ||
method = req.body[key].toLowerCase(); | ||
delete req.body[key]; | ||
} | ||
|
||
// check X-HTTP-Method-Override | ||
if (req.headers['x-http-method-override']) { | ||
method = req.headers['x-http-method-override'].toLowerCase(); | ||
} | ||
|
||
// replace | ||
if (supports(method)) req.method = method.toUpperCase(); | ||
|
||
next(); | ||
}; | ||
}; | ||
|
||
/** | ||
* Check if node supports `method`. | ||
*/ | ||
|
||
function supports(method) { | ||
return ~methods.indexOf(method); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "method-override", | ||
"description": "method override", | ||
"version": "1.0.0", | ||
"author": { | ||
"name": "Jonathan Ong", | ||
"email": "[email protected]", | ||
"url": "http://jongleberry.com", | ||
"twitter": "https://twitter.com/jongleberry" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/expressjs/method-override.git" | ||
}, | ||
"bugs": { | ||
"mail": "[email protected]", | ||
"url": "https://github.com/expressjs/method-override/issues" | ||
}, | ||
"dependencies": { | ||
"methods": "*" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^1.17.0", | ||
"should": "^3.0.0", | ||
"supertest": "*", | ||
"connect": "*" | ||
}, | ||
"scripts": { | ||
"test": "make test" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
var connect = require('connect'); | ||
var request = require('supertest'); | ||
|
||
var app = connect(); | ||
var server = app.listen(); | ||
|
||
app.use(require('../')()); | ||
|
||
app.use(function(req, res){ | ||
res.end(req.method); | ||
}); | ||
|
||
describe('methodOverride()', function(){ | ||
it('should not touch the method by default', function(done){ | ||
request(server) | ||
.get('/') | ||
.expect('GET', done); | ||
}) | ||
|
||
it('should be case in-sensitive', function(done){ | ||
request(server) | ||
.post('/') | ||
.set('Content-Type', 'application/x-www-form-urlencoded') | ||
.set('X-HTTP-Method-Override', 'DELETE') | ||
.expect('DELETE', done); | ||
}) | ||
|
||
it('should ignore invalid methods', function(done){ | ||
request(server) | ||
.post('/') | ||
.set('Content-Type', 'application/x-www-form-urlencoded') | ||
.set('X-HTTP-Method-Override', 'POST') | ||
.expect('POST', done); | ||
}) | ||
}) |