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

Use qs stringify for post body #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

bantic
Copy link
Contributor

@bantic bantic commented Jun 29, 2011

This uses qs.stringify to turn options.body into a string if it is an object in Browser.post. I am not sure the best way to determine if a variable is an object so I used Object.prototype.toString.call(options.body) (which I saw used in node-querystring (https://github.com/visionmedia/node-querystring/blob/master/lib/querystring.js#L17).

@@ -157,6 +158,9 @@ Browser.prototype.request = function(method, path, options, fn, saveHistory){

// Request body
if (options.body) {
if ('[object Object]' === Object.prototype.toString.call(options.body)) {
options.body = qs.stringify(options.body);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to abstract these out a little with an object mapping content types to functions say something like:

exports.stringify['application/x-www-form-urlencoded'] = qs.stringify

so then we could have application/json etc

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 this pull request may close these issues.

2 participants