Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/client_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down