Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for content-type, updated buffer handling, and better query string parse #25

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
language: node_js
node_js:
- 0.10
- 0.10
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this

2 changes: 1 addition & 1 deletion lib/middleware/multipart-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var formidable = require('formidable')

module.exports = function () {
return function (request, response, next) {
if (!request.method.match(/(PUT|POST|OPTIONS)/)) {
if (!request.method.match(/(PUT|POST|OPTIONS)/) || request.headers['content-type'] == undefined) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use just !request.headers['content-type']

return next()
}
if (request.headers['content-type'].match(/multipart\/form-data/)) {
Expand Down
8 changes: 4 additions & 4 deletions lib/middleware/payload-parser.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var querystring = require('querystring'),
var qs = require('qs'),
BufferJoiner = require('bufferjoiner')

module.exports = function () {
return function (request, response, next) {
if (!request.method.match(/(PUT|POST|OPTIONS)/)) {
if (!request.method.match(/(PUT|POST|OPTIONS)/) || !request.headers['content-type']) {
return next()
}
request.rawBody = new BufferJoiner()
Expand All @@ -14,7 +14,7 @@ module.exports = function () {
request.rawBody = request.rawBody.join()
if (!request.headers['content-type']) return
if (request.headers['content-type'].match(/application\/x-www-form-urlencoded/)) {
request.body = querystring.parse(request.rawBody.toString('utf8'))
request.body = qs.parse(request.rawBody.toString('utf8'))
} else if (request.headers['content-type'].match(/application\/json/)) {
try {
request.body = JSON.parse(request.rawBody.toString('utf8'))
Expand All @@ -26,4 +26,4 @@ module.exports = function () {
})
next()
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"should": "0.6.1",
"request": "2.9.x"
}
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this