2 * index.js: Top level include for node-http-proxy helpers
4 * (C) 2010 Nodejitsu Inc.
9 var fs = require('fs'),
10 path = require('path');
12 var fixturesDir = path.join(__dirname, '..', 'fixtures');
16 // Returns the necessary `https` credentials.
18 Object.defineProperty(exports, 'https', {
22 key: fs.readFileSync(path.join(fixturesDir, 'agent2-key.pem'), 'utf8'),
23 cert: fs.readFileSync(path.join(fixturesDir, 'agent2-cert.pem'), 'utf8')
29 // @protocols {Object}
30 // Returns an object representing the desired protocols
31 // for the `proxy` and `target` server.
33 Object.defineProperty(exports, 'protocols', {
35 delete this.protocols;
36 return this.protocols = {
37 target: exports.argv.target || 'http',
38 proxy: exports.argv.proxy || 'http'
45 // Returns an auto-incrementing port for tests.
47 Object.defineProperty(exports, 'nextPort', {
49 var current = this.port || 9050;
50 this.port = current + 1;
56 // @nextPortPair {Object}
57 // Returns an auto-incrementing pair of ports for tests.
59 Object.defineProperty(exports, 'nextPortPair', {
62 target: this.nextPort,
69 // ### function describe(prefix)
70 // #### @prefix {string} Prefix to use before the description
72 // Returns a string representing the protocols that this suite
73 // is testing based on CLI arguments.
75 exports.describe = function (prefix, base) {
76 prefix = prefix || '';
77 base = base || 'http';
79 function protocol(endpoint) {
80 return exports.protocols[endpoint] === 'https'
93 ].filter(Boolean).join('/');
97 // Expose the CLI arguments
99 exports.argv = require('optimist').argv;
102 // Export additional helpers for `http` and `websockets`.
104 exports.http = require('./http');
105 exports.ws = require('./ws');