Skip to content

Commit

Permalink
Merge pull request #8 from coderhaoxin/json-patch
Browse files Browse the repository at this point in the history
add support for json patch
  • Loading branch information
dead-horse committed Nov 27, 2014
2 parents 74f8acd + 1843978 commit 977a329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -34,7 +34,7 @@ module.exports = function (opts) {
return yield* next;
}

if (this.request.is('application/json', 'application/vnd.api+json', 'application/csp-report')) {
if (this.request.is('application/json', 'application/json-patch+json', 'application/vnd.api+json', 'application/csp-report')) {
this.request.body = yield parse.json(this, jsonOpts);
} else if (this.request.is('application/x-www-form-urlencoded')) {
this.request.body = yield parse.form(this, formOpts);
Expand Down
13 changes: 13 additions & 0 deletions test/middleware.test.js
Expand Up @@ -58,6 +58,19 @@ describe('test/middleware.test.js', function () {
.expect({ foo: 'bar' }, done);
});

it('should parse json patch', function (done) {
var app = App();
app.use(function *() {
this.request.body.should.eql( [{op: 'add', path: '/foo', value: 'bar'}] );
this.body = this.request.body;
});
request(app.listen())
.patch('/')
.set('Content-type', 'application/json-patch+json')
.send('[{"op": "add", "path": "/foo", "value": "bar"}]')
.expect([{op: 'add', path: '/foo', value: 'bar'}], done);
});

it('should json body reach the limit size', function (done) {
var app = App({jsonLimit: 100});
app.use(function *() {
Expand Down

0 comments on commit 977a329

Please sign in to comment.