Skip to content

Commit

Permalink
fea: use query string to parse payload when content type is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
welefen committed Feb 24, 2016
1 parent 33918c4 commit 4c9def1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/middleware/parse_querystring_payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class extends think.middleware.base {
}

let contentType = http.type();
if(contentType.indexOf('application/x-www-form-urlencoded') === -1){
if(contentType && contentType.indexOf('application/x-www-form-urlencoded') === -1){
return;
}

Expand Down
17 changes: 17 additions & 0 deletions test/middleware/parse_querystring_payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ describe('middleware/parse_json_payload', function(){
it('parse_querystring_payload, getPayload, contentType fail', function(done){
getHttp('', {
payload: '',
type: function(){return 'content'},
//_post: {name: 'thinkjs'},
getPayload: function(){
return Promise.resolve('name=thinkjs1')
Expand All @@ -87,6 +88,22 @@ describe('middleware/parse_json_payload', function(){
})
})
})
it('parse_querystring_payload, getPayload, contentType empty', function(done){
getHttp('', {
payload: '',
//_post: {name: 'thinkjs'},
getPayload: function(){
return Promise.resolve('name=thinkjs1')
}
}).then(function(http){
think.middleware('parse_querystring_payload', http).then(function(data){
assert.deepEqual(http._post, {name: 'thinkjs1'});
done();
}).catch(function(err){
console.log(err.stack)
})
})
})
it('parse_querystring_payload, getPayload', function(done){
getHttp('', {
payload: '',
Expand Down

0 comments on commit 4c9def1

Please sign in to comment.