Throw a more helpful error if a client driver is created with an invalid URL.
This commit is contained in:
@@ -20,6 +20,9 @@ var Client = function(_url, options) {
|
||||
var uri = url.parse(this.url),
|
||||
auth = uri.auth && new Buffer(uri.auth, 'utf8').toString('base64');
|
||||
|
||||
if (this.VALID_PROTOCOLS.indexOf(uri.protocol) < 0)
|
||||
throw new Error(this.url + ' is not a valid WebSocket URL');
|
||||
|
||||
this._pathname = (uri.pathname || '/') + (uri.search || '');
|
||||
|
||||
this._headers.set('Host', uri.host);
|
||||
@@ -41,6 +44,8 @@ Client.generateKey = function() {
|
||||
};
|
||||
|
||||
var instance = {
|
||||
VALID_PROTOCOLS: ['ws:', 'wss:'],
|
||||
|
||||
proxy: function(origin, options) {
|
||||
return new Proxy(this, origin, options);
|
||||
},
|
||||
|
||||
@@ -109,6 +109,16 @@ test.describe("Client", function() { with(this) {
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("with an invalid URL", function() { with(this) {
|
||||
define("url", function() { return "stream.wikimedia.org/rc" })
|
||||
|
||||
it("throws an error", function() { with(this) {
|
||||
var message
|
||||
try { driver() } catch (e) { message = e.message }
|
||||
assertEqual( "stream.wikimedia.org/rc is not a valid WebSocket URL", message )
|
||||
}})
|
||||
}})
|
||||
|
||||
describe("with custom headers", function() { with(this) {
|
||||
before(function() { with(this) {
|
||||
driver().setHeader("User-Agent", "Chrome")
|
||||
|
||||
Reference in New Issue
Block a user