Skip to content
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

json: true sends "true" as request body no matter what #134

Closed
bjoerge opened this issue Oct 5, 2016 · 5 comments
Closed

json: true sends "true" as request body no matter what #134

bjoerge opened this issue Oct 5, 2016 · 5 comments
Milestone

Comments

@bjoerge
Copy link
Contributor

bjoerge commented Oct 5, 2016

xhr({body: {foo: 'bar'}, json: true})

will post true as request body.

It even sends false as request body if passing json: false.

According to request docs, the json flag is only used as a modifier to body:

json - sets body to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as JSON.
(https://github.com/request/request/blob/master/README.md#requestoptions-callback)

@bjoerge bjoerge changed the title json: true sends true as request body no matter what json: true sends "true" as request body no matter what Oct 5, 2016
@naugtur naugtur added this to the v3.0 milestone Oct 5, 2016
@wesleytodd
Copy link

Hey, sorry if this is late to the party, or if I missed anything somewhere in #136, but it seems to me like this not working is a bug in the current branch that can be fixed before a major version bump. Something like this could fix it until #135 goes through:

body = JSON.stringify(options.json === true ? body : options.json)

This bug blocks a bunch of legitimate use cases (body-less DELETE requests which expect json back, for example) in the 2.0 branch, and so I think holding up a release here is a mistake, but that is just my personal opinion.

I can submit the PR for this if it seems like a good change

@naugtur
Copy link
Owner

naugtur commented Nov 11, 2016

Very good point. Would you by any chance like to contribute a testcase for that?

I'll look into it more tomorrow.

@naugtur
Copy link
Owner

naugtur commented Nov 12, 2016

Done, #139

@wesleytodd
Copy link

Looks like you have it all covered? Let me know if you need anything else to help out! Otherwise good work!!

naugtur added a commit that referenced this issue Nov 20, 2016
…equest

Align json option with request, improved to include input from #134 comments
@naugtur
Copy link
Owner

naugtur commented Nov 20, 2016

merged, releasing 2.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants