Skip to content

Commit

Permalink
Merge d2042df into 7cd5983
Browse files Browse the repository at this point in the history
  • Loading branch information
DonutEspresso committed Oct 11, 2018
2 parents 7cd5983 + d2042df commit 716cd1c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/HttpClient.js
Expand Up @@ -8,7 +8,7 @@ var http = require('http');
var https = require('https');
var net = require('net');
var os = require('os');
var querystring = require('querystring');
var qs = require('qs');
var url = require('url');
var util = require('util');

Expand Down Expand Up @@ -957,7 +957,7 @@ HttpClient.prototype._options = function (method, options) {
if (opts.query &&
Object.keys(opts.query).length &&
opts.path.indexOf('?') === -1) {
opts.path += '?' + querystring.stringify(opts.query);
opts.path += '?' + qs.stringify(opts.query);
}

if (this.socketPath) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -68,6 +68,7 @@
"lru-cache": "^4.0.1",
"mime": "^2.2.0",
"once": "^1.4.0",
"qs": "^6.5.2",
"restify-errors": "^6.0.0",
"semver": "^5.0.1",
"tunnel-agent": "^0.6.0",
Expand Down
52 changes: 52 additions & 0 deletions test/querystring.test.js
Expand Up @@ -65,6 +65,31 @@ describe('query string parameters', function () {
CLIENT.get('/foo', done);
});

it('should support serializing objects into associative array',
function (done) {
SERVER.get('/foo', function (req, res, next) {
assert.deepEqual(req.query, {
foo: {
a: 'coffee',
b: 'beans'
}
});
res.send(200);
return next();
});

CLIENT = clients.createJsonClient({
url: 'http://localhost:3000/foo',
query: {
foo: {
a: 'coffee',
b: 'beans'
}
}
});
CLIENT.get('/foo', done);
});

it('should prefer query option over query in url', function (done) {
SERVER.get('/foo', function (req, res, next) {
assert.deepEqual(req.query, {
Expand Down Expand Up @@ -124,6 +149,33 @@ describe('query string parameters', function () {
}, done);
});

it('should support serializing objects into associative array',
function (done) {
SERVER.get('/foo', function (req, res, next) {
assert.deepEqual(req.query, {
foo: {
a: 'coffee',
b: 'beans'
}
});
res.send(200);
return next();
});

CLIENT = clients.createJsonClient({
url: 'http://localhost:3000/foo'
});
CLIENT.get({
path: '/foo',
query: {
foo: {
a: 'coffee',
b: 'beans'
}
}
}, done);
});

it('should prefer query string in path over query option',
function (done) {
SERVER.get('/foo', function (req, res, next) {
Expand Down

0 comments on commit 716cd1c

Please sign in to comment.