/** * @file * Small utility to test the HTTP response of a set of servers to a given URL. * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it * and/or modify it under the terms of the Do What The Fuck You Want * To Public License, Version 2, as published by Sam Hocevar. See * http://sam.zoy.org/wtfpl/COPYING for more details. */ var sys = require('sys'); var url = require('url'); var http = require('http'); if (process.argv.length < 4) { sys.print('Usage: cluster-test.js [url] [server1] ... [serverN]\n'); process.exit(1); } // Parse arguments. var hosts = process.argv; hosts.shift(); // Node executable. hosts.shift(); // Path to the JS file. var target_url = hosts.shift(); sys.print('Testing URL: ' + target_url + '\n\n'); var parsedURL = url.parse(target_url, true); hosts.forEach(function(host) { var client = http.createClient(80, host); // Error handling (failure to connect to the host will trigger this). client.addListener('error', function(exception) { sys.print(host + ' ' + exception.message + '\n') }); // Launch the request. var request = client.request('GET', (parsedURL.pathname || '/') + (parsedURL.search || ''), { host: parsedURL.host }); // Error handling (technical failures during the request might trigger this). request.addListener('error', function(exception) { sys.print(host + ' ' + exception.message + '\n') }); // Received a valid response. request.addListener('response', function(response) { sys.print(host + ' ' + response.statusCode + '\n'); }); request.end(); });