diff --git a/lib/client.js b/lib/client.js index b875461..23299f1 100644 --- a/lib/client.js +++ b/lib/client.js @@ -31,16 +31,22 @@ function Client(options, isSecure) { // If a string URI is passed in, converts to URI fields if (typeof options === 'string') { - options = url.parse(options) - options.host = options.hostname - options.path = options.pathname + var parsedUrl = url.parse(options) + options = {} + options.host = parsedUrl.hostname + options.path = parsedUrl.pathname + options.port = parsedUrl.port + if (parsedUrl.query) + options.path += '?' + parsedUrl.query } if (typeof options.url !== 'undefined') { - var parsedUrl = url.parse(options.url); - options.host = parsedUrl.hostname; - options.path = parsedUrl.pathname; - options.port = parsedUrl.port; + var parsedUrl = url.parse(options.url) + options.host = parsedUrl.hostname + options.path = parsedUrl.pathname + options.port = parsedUrl.port + if (parsedUrl.query) + options.path += '?' + parsedUrl.query } // Set the HTTP request headers diff --git a/test/client_test.js b/test/client_test.js index 77cba21..c9454b4 100644 --- a/test/client_test.js +++ b/test/client_test.js @@ -59,6 +59,30 @@ vows.describe('Client').addBatch({ assert.deepEqual(topic, { host: 'localhost', port: 9999, path: '/', method: 'POST', headers: headers }) } } + // Test with a string for options, including a query string in the path + , 'with a string URI for options that includes a path with a query string' : { + topic: function () { + var client = new Client('http://localhost:9999?test=test', false) + return client.options + } + , 'parses the string URI into URI fields' : function (topic) { + assert.strictEqual(topic.host, 'localhost') + assert.strictEqual(topic.path, '/?test=test') + assert.equal(topic.port, 9999) + } + } + // Test with options object, including a path with a query string. + , 'with a string URI for options that includes a query string' : { + topic: function () { + var client = new Client({host:'localhost', path : '/?test=test', port : 9999}, false) + return client.options + } + , 'parses the string URI into URI fields' : function (topic) { + assert.strictEqual(topic.host, 'localhost') + assert.strictEqual(topic.path, '/?test=test') + assert.equal(topic.port, 9999) + } + } // Test passing HTTP Basic authentication credentials , 'with basic auth passed' : { topic: function () {