-
Notifications
You must be signed in to change notification settings - Fork 132
Add support for JSON Patch, JSON API and CSP report #161
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
Conversation
index.js
Outdated
@@ -70,7 +70,7 @@ function requestbody(opts) { | |||
// only parse the body on specifically chosen methods | |||
if (opts.parsedMethods.includes(ctx.method.toUpperCase())) { | |||
try { | |||
if (opts.json && ctx.is('json')) { | |||
if (opts.json && ctx.is('json', 'application/json-patch+json')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking we should just borrow the list if JSON content types from koa-bodyparser https://github.com/koajs/bodyparser/blob/master/index.js#L45-L50
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to use +json
instead of ['application/json-patch+json', 'application/vnd.api+json']
so it would support any media types that represent a JSON document (see Structured Syntax Name Suffixes)?
if (opts.json && ctx.is('json', '+json', 'application/csp-report'))
Or should this lib only handle a few explicit types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MarkHerhold I just pushed a commit that adds support for the same types as in bodyparser (PR description updated).
- application/json-patch+json - application/vnd.api+json - application/csp-report
@MarkHerhold anything else I can do to get it merged? |
Oh, sorry. Thanks for putting this back on my radar. Reviewing now... |
Looks great, thanks @simonbrunel and @sedenardi |
published as 4.1.1 |
@MarkHerhold Thanks, will test 4.1.1 asap. |
Everything looks good. Thanks again @MarkHerhold for getting to this so quickly. |
Similar to koajs/bodyparser/pull/8, adds support for JSON Patch, JSON API and CSP report:
application/json-patch+json
(https://tools.ietf.org/html/rfc6902)application/vnd.api+json
(https://jsonapi.org/)application/csp-report
(https://www.w3.org/TR/CSP2/#violation-reports)Extends #160 (though this PR doesn't introduce new option)
Tests added: