Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
fix(api): reject requests with bad content-types
Browse files Browse the repository at this point in the history
Only blank and application/json are allow.

Closes #199
  • Loading branch information
seanmonstar committed Jan 24, 2015
1 parent 281b15a commit 2667228
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/server.js
Expand Up @@ -57,6 +57,22 @@ exports.create = function createServer() {
delete route.config.response;
});
}

// require json by default
routes.forEach(function(route) {
var method = route.method.toUpperCase();
if (method !== 'GET' && method !== 'HEAD') {
if (!route.config.payload) {
route.config.payload = { allow: 'application/json' };
}
logger.verbose('route.payload', {
url: route.url,
method: method,
payload: route.config.payload
});
}
});

server.route(routes);

// hapi internal logging: server and request
Expand Down
15 changes: 15 additions & 0 deletions test/api.js
Expand Up @@ -200,6 +200,21 @@ describe('/v1', function() {
});
});

describe('content-type', function() {
it('should fail if not application/json or empty', function() {
return Server.api.post({
url: '/authorization',
headers: {
'content-type': 'text/plain'
},
payload: authParams()
}).then(function(res) {
console.log(res);
assert.equal(res.statusCode, 415);
});
});
});

describe('?client_id', function() {

it('is required', function(done) {
Expand Down

0 comments on commit 2667228

Please sign in to comment.