Permalink
Browse files

0.0.4 + querystring changes

  • Loading branch information...
1 parent c5ded1d commit c4a282028f7abf5e4693638567c37476dc4e996e @tim-smart committed Feb 22, 2011
Showing with 39 additions and 11 deletions.
  1. +0 −1 deps/querystring/index.js
  2. +27 −0 deps/querystring/index.js
  3. +11 −9 index.js
  4. +1 −1 package.json
View
@@ -0,0 +1,27 @@
+/*
+ * querystring.js
+ * - node.js module providing "parse" and "stringify" methods
+ * to turn query strings into objects and to turn objects
+ * into query string, respectively
+ *
+ * This module is basically a stub loader. It will load both
+ * sub-modules and put the respective exports under the same
+ * namespace. You may choose to load the sub-modules
+ * individually if you only need the functionality of one.
+ *
+ * Chad Etzel
+ *
+ * Based on YUI "querystring-parse.js" module
+ * http://github.com/isaacs/yui3/tree/master/src/querystring/js
+ *
+ * Copyright (c) 2009, Yahoo! Inc. and Chad Etzel
+ * BSD License (see LICENSE.md for info)
+ *
+ */
+
+[
+ require("./querystring-parse"),
+ require("./querystring-stringify")
+].forEach(function (q) {
+ for (var i in q) if (q.hasOwnProperty(i)) exports[i] = q[i];
+});
View
@@ -95,29 +95,31 @@ Client.prototype._request = function (method, options, callback) {
options.params = this.params;
}
- if ('object' === typeof options.params) {
- if (this.params) {
- mixin(options.params, this.params);
- }
- options.path += '?' + querystring.stringify(options.params);
- } else {
- options.path += '?' + options.params;
+ if (this.params) {
+ mixin(options.params, this.params);
}
+
+ options.path += '?' + querystring.stringify(options.params);
}
options.type = options.type || this.type;
if ('object' === typeof options.body) {
if ('json' === options.type) {
- options.headers['Content-Type'] = 'application/json';
options.body = JSON.stringify(options.body);
} else {
- options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
+ options.type = 'form';
options.body = querystring.stringify(options.body);
}
}
if (options.body) {
options.headers['Content-Length'] = Buffer.byteLength(options.body);
+
+ if ('json' === options.type) {
+ options.headers['Content-Type'] = 'application/json';
+ } else if ('form' === options.type) {
+ options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
+ }
} else if ('DELETE' === method ||
'PUT' === method ||
'POST' === method) {
View
@@ -1,6 +1,6 @@
{
"name": "nest",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "A Node HTTP client aimed at REST API's.",
"repository": {
"type": "git",

0 comments on commit c4a2820

Please sign in to comment.