GithubHelp home page GithubHelp logo

Comments (13)

jonathanong avatar jonathanong commented on April 27, 2024

yep i agree. though, really, the issue is with the .is() function. or perhaps i'm using it incorrectly.

@dougwilson ?

from body-parsers.

jonathanong avatar jonathanong commented on April 27, 2024

are these custom media types using the +json suffix?

from body-parsers.

hallas avatar hallas commented on April 27, 2024

It's my understanding that they should carry the +json suffix to be json formatted

from body-parsers.

mdvorak avatar mdvorak commented on April 27, 2024

For my case, yes, I use +json suffix to specify format, as is good practice. .is() should pick that up, althou it doesn't (so that's another issue). But in any case, it is just good practice to use +json suffix, it is not mandatory. There is nowhere specified, that application/x.cucumber cannot be json formatted, the contract between server and client specifies that. request.json() should not make that decision for you.
Just my opinion.

from body-parsers.

dougwilson avatar dougwilson commented on April 27, 2024

@jonathanong the issue is that the user does not have the ability to influence the line https://github.com/koajs/body-parsers/blob/master/index.js#L28 , so they have no way to let whatever Content-Type be interpreted as json that they want.

from body-parsers.

jonathanong avatar jonathanong commented on April 27, 2024

@dougwilson should changing it to +json make it always work?

from body-parsers.

dougwilson avatar dougwilson commented on April 27, 2024

You can make it ['json', '+json'], but that still won't help someone who wants to use Content-Type: application/x-my-type, especially if they don't have control over it.

from body-parsers.

hallas avatar hallas commented on April 27, 2024

I think we need a way to pass an optional type to the json parsing bit then?

from body-parsers.

jonathanong avatar jonathanong commented on April 27, 2024

yep.

@dougwilson how was making a generic body parsing module? was kind of waiting for that, at least the body reading part.

from body-parsers.

mdvorak avatar mdvorak commented on April 27, 2024

I would still recommend just removing the check, it is redundant if you follow example from Koala:

switch (this.request.is('json', 'urlencoded', 'multipart', 'image/*')) {
case 'json':
  var body = yield* this.request.json();
  break;
case 'urlencoded':
  var body = yield* this.request.urlencoded();
  break

it means, that the check will be performed for json always twice. And more, if you allow passing an argument, the argument will have to be duplicated for both is and json. Redundancy.
Just consider it. Thanks.

from body-parsers.

jonathanong avatar jonathanong commented on April 27, 2024

yup i don't see why not. hopefully i'll get to it tonight

from body-parsers.

mdvorak avatar mdvorak commented on April 27, 2024

Great, thanks!

from body-parsers.

fengmk2 avatar fengmk2 commented on April 27, 2024

Great! LGTM.

from body-parsers.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.