diff --git a/README.md b/README.md index 6b97fe5..2a8baa5 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ Google it. -A, --amount the amount of persistent connections to generate -C, --concurrent how many concurrent-connections per second -M, --messages messages to be send per connection + -H, --header [header] a header to pass to each connection -P, --protocol WebSocket protocol version -B, --buffer size of the messages that are send -W, --workers workers to be spawned diff --git a/bin/thor b/bin/thor index 9db08f2..564b046 100755 --- a/bin/thor +++ b/bin/thor @@ -7,6 +7,14 @@ var Metrics = require('../metrics') , path = require('path') , os = require('os'); +function collect(val, memo) { + if(!memo){ + memo = []; + } + memo.push(val); + return memo; +} + // // Setup the Command-Line Interface. // @@ -16,6 +24,7 @@ cli.usage('[options] ws://localhost') .option('-A, --amount ', 'the amount of persistent connections to generate', parseInt, 10000) .option('-C, --concurrent ', 'how many concurrent-connections per second', parseInt, 0) .option('-M, --messages ', 'messages to be send per connection', parseInt, 1) + .option('-H, --header [header]', 'a header to pass to each connection', collect, []) .option('-P, --protocol ', 'WebSocket protocol version', parseInt, 13) .option('-B, --buffer ', 'size of the messages that are send', parseInt, 1024) .option('-W, --workers ', 'workers to be spawned', parseInt, os.cpus().length) @@ -47,6 +56,22 @@ var cluster = require('cluster') , received = 0 , robin = []; +// +// Process headers +// +var headers = {}; +cli.header.forEach(function(header){ + var keyValue = header.split(':'); + var key = keyValue[0]; + var value = keyValue[1]; + if(!key || !value){ + console.warn('Header \'' + + '\' is wrongly defined. A header should looks like \'key:value\'.'); + return; + } + headers[key.trim()] = value.trim(); +}); +console.log(headers); + cluster.setupMaster({ exec: path.resolve(__dirname, '../mjolnir.js') , silent: false @@ -56,7 +81,8 @@ cluster.setupMaster({ : path.resolve(__dirname, '../generator.js'), cli.protocol, !!cli.masked, - !!cli.binary + !!cli.binary, + headers ] }); diff --git a/mjolnir.js b/mjolnir.js index c22f517..5ac4a2d 100644 --- a/mjolnir.js +++ b/mjolnir.js @@ -14,7 +14,8 @@ var session = require(process.argv[2]); // var masked = process.argv[4] === 'true' , binary = process.argv[5] === 'true' - , protocol = +process.argv[3] || 13; + , protocol = +process.argv[3] || 13 + , headers = process.argv[6]; process.on('message', function message(task) { var now = Date.now(); @@ -41,7 +42,8 @@ process.on('message', function message(task) { if (!task.url) return; var socket = new Socket(task.url, { - protocolVersion: protocol + protocolVersion: protocol, + headers: headers }); socket.on('open', function open() { diff --git a/package.json b/package.json index bdfe97b..26ef0aa 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "author": "Arnout Kazemier ", "license": "MIT", "dependencies": { - "commander": "1.1.x", + "commander": "2.9.0", "async": "0.2.x", "tab": "0.1.x", "colors": "0.6.x",