From 9cecd97153ccce4f81c5eda35a49079e651fb27a Mon Sep 17 00:00:00 2001 From: indexzero Date: Sat, 9 Mar 2013 01:43:25 -0500 Subject: [PATCH] [minor] s/function(/function (/ s/){/) {/ --- README.md | 12 ++++++------ .../simple-balancer-with-websockets.js | 2 +- examples/helpers/store.js | 4 ++-- examples/http/latent-proxy.js | 2 +- examples/http/standalone-proxy.js | 2 +- lib/node-http-proxy.js | 2 +- lib/node-http-proxy/http-proxy.js | 18 +++++++++--------- lib/node-http-proxy/routing-proxy.js | 2 +- test/core/common.js | 16 ++++++++-------- test/core/pummel/test-http-upload-timeout.js | 10 +++++----- test/core/simple/test-http-chunked.js | 14 +++++++------- test/core/simple/test-http-client-abort.js | 14 +++++++------- test/core/simple/test-http-client-abort2.js | 8 ++++---- .../core/simple/test-http-client-upload-buf.js | 16 ++++++++-------- test/core/simple/test-http-client-upload.js | 16 ++++++++-------- test/core/simple/test-http-contentLength0.js | 6 +++--- test/core/simple/test-http-eof-on-connect.js | 8 ++++---- test/core/simple/test-http-extra-response.js | 14 +++++++------- test/core/simple/test-http-head-request.js | 10 +++++----- .../test-http-head-response-has-no-body-end.js | 10 +++++----- .../test-http-head-response-has-no-body.js | 10 +++++----- test/core/simple/test-http-host-headers.js | 4 ++-- .../test-http-many-keep-alive-connections.js | 14 +++++++------- .../simple/test-http-multi-line-headers.js | 10 +++++----- test/core/simple/test-http-proxy.js | 18 +++++++++--------- test/core/simple/test-http-response-close.js | 12 ++++++------ .../simple/test-http-server-multiheaders.js | 4 ++-- test/core/simple/test-http-set-cookies.js | 18 +++++++++--------- test/core/simple/test-http-status-code.js | 8 ++++---- test/core/simple/test-http-upgrade-server2.js | 16 ++++++++-------- test/core/simple/test-http.js | 18 +++++++++--------- test/helpers/http.js | 8 ++++---- 32 files changed, 163 insertions(+), 163 deletions(-) diff --git a/README.md b/README.md index d105936..617c49f 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,7 @@ var server = httpProxy.createServer(function (req, res, proxy) { }); }); -server.proxy.on('end', function() { +server.proxy.on('end', function () { console.log("The request was proxied."); }); @@ -325,7 +325,7 @@ var certs = { // var options = { https: { - SNICallback: function(hostname){ + SNICallback: function (hostname) { return certs[hostname]; } }, @@ -424,8 +424,8 @@ var server = httpProxy.createServer( options ); -server.listen(port, function() { ... }); -server.on('upgrade', function(req, socket, head) { +server.listen(port, function () { ... }); +server.on('upgrade', function (req, socket, head) { server.proxy.proxyWebSocketRequest(req, socket, head); }); ``` @@ -453,7 +453,7 @@ var server = http.createServer(function (req, res) { proxy.proxyRequest(req, res); }); -server.on('upgrade', function(req, socket, head) { +server.on('upgrade', function (req, socket, head) { // // Proxy websocket requests too // @@ -478,7 +478,7 @@ var server = httpProxy.createServer(function (req, res, proxy) { }); }) -server.on('upgrade', function(req, socket, head) { +server.on('upgrade', function (req, socket, head) { // // Put your custom server logic here // diff --git a/examples/balancer/simple-balancer-with-websockets.js b/examples/balancer/simple-balancer-with-websockets.js index f27c9ef..04564ce 100644 --- a/examples/balancer/simple-balancer-with-websockets.js +++ b/examples/balancer/simple-balancer-with-websockets.js @@ -50,7 +50,7 @@ var server = http.createServer(function (req, res) { // Get the 'next' proxy and send the upgrade request // -server.on('upgrade', function(req, socket, head) { +server.on('upgrade', function (req, socket, head) { nextProxy().proxyWebSocketRequest(req, socket, head); }); diff --git a/examples/helpers/store.js b/examples/helpers/store.js index 62a627e..e286057 100644 --- a/examples/helpers/store.js +++ b/examples/helpers/store.js @@ -39,10 +39,10 @@ Store.prototype = { res.end() } var url = req.url.split('?').shift() - if(url === '/') { + if (url === '/') { console.log('get index') return send(Object.keys(store.store)) - } else if(req.method == 'GET') { + } else if (req.method == 'GET') { var obj = store.get (url) send(obj || {error: 'not_found', url: url}, obj ? 200 : 404) } else { diff --git a/examples/http/latent-proxy.js b/examples/http/latent-proxy.js index 5da5598..2063d0e 100644 --- a/examples/http/latent-proxy.js +++ b/examples/http/latent-proxy.js @@ -34,7 +34,7 @@ var util = require('util'), // httpProxy.createServer(function (req, res, proxy) { var buffer = httpProxy.buffer(req); - setTimeout(function() { + setTimeout(function () { proxy.proxyRequest(req, res, { port: 9000, host: 'localhost', diff --git a/examples/http/standalone-proxy.js b/examples/http/standalone-proxy.js index 9ffa817..e1b1011 100644 --- a/examples/http/standalone-proxy.js +++ b/examples/http/standalone-proxy.js @@ -35,7 +35,7 @@ var util = require('util'), var proxy = new httpProxy.RoutingProxy(); http.createServer(function (req, res) { var buffer = httpProxy.buffer(req); - setTimeout(function() { + setTimeout(function () { proxy.proxyRequest(req, res, { port: 9000, host: 'localhost', diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index b9bd914..24c1108 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -211,7 +211,7 @@ exports.createServer = function () { // __events will be lost.__ // // var buffer = httpProxy.buffer(req); -// fs.readFile(path, function(){ +// fs.readFile(path, function () { // httpProxy.proxyRequest(req, res, host, port, buffer); // }); // diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index a79a125..8df6174 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -134,7 +134,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { // * `x-forwarded-port`: Port of the original request. // if (this.enable.xforward && req.connection && req.socket) { - if (req.headers['x-forwarded-for']){ + if (req.headers['x-forwarded-for']) { var addressToAppend = "," + req.connection.remoteAddress || req.socket.remoteAddress; req.headers['x-forwarded-for'] += addressToAppend; } @@ -142,7 +142,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { req.headers['x-forwarded-for'] = req.connection.remoteAddress || req.socket.remoteAddress; } - if (req.headers['x-forwarded-port']){ + if (req.headers['x-forwarded-port']) { var portToAppend = "," + req.connection.remotePort || req.socket.remotePort; req.headers['x-forwarded-port'] += portToAppend; } @@ -150,7 +150,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { req.headers['x-forwarded-port'] = req.connection.remotePort || req.socket.remotePort; } - if (req.headers['x-forwarded-proto']){ + if (req.headers['x-forwarded-proto']) { var protoToAppend = "," + getProto(req); req.headers['x-forwarded-proto'] += protoToAppend; } @@ -302,7 +302,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { }); // Set the headers of the client response - Object.keys(response.headers).forEach(function(key){ + Object.keys(response.headers).forEach(function (key) { res.setHeader(key, response.headers[key]); }); res.writeHead(response.statusCode); @@ -438,7 +438,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // * `x-forwarded-port`: Port of the original request. // if (this.enable.xforward && req.connection) { - if (req.headers['x-forwarded-for']){ + if (req.headers['x-forwarded-for']) { var addressToAppend = "," + req.connection.remoteAddress || socket.remoteAddress; req.headers['x-forwarded-for'] += addressToAppend; } @@ -446,7 +446,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) req.headers['x-forwarded-for'] = req.connection.remoteAddress || socket.remoteAddress; } - if (req.headers['x-forwarded-port']){ + if (req.headers['x-forwarded-port']) { var portToAppend = "," + req.connection.remotePort || socket.remotePort; req.headers['x-forwarded-port'] += portToAppend; } @@ -454,7 +454,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) req.headers['x-forwarded-port'] = req.connection.remotePort || socket.remotePort; } - if (req.headers['x-forwarded-proto']){ + if (req.headers['x-forwarded-proto']) { var protoToAppend = "," + (req.connection.pair ? 'wss' : 'ws'); req.headers['x-forwarded-proto'] += protoToAppend; } @@ -577,7 +577,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // If the incoming `proxySocket` socket closes, then // detach all event listeners. // - listeners.onIncomingClose = function() { + listeners.onIncomingClose = function () { reverseProxy.incoming.socket.destroy(); detach(); @@ -589,7 +589,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) // If the `reverseProxy` socket closes, then detach all // event listeners. // - listeners.onOutgoingClose = function() { + listeners.onOutgoingClose = function () { proxySocket.destroy(); detach(); } diff --git a/lib/node-http-proxy/routing-proxy.js b/lib/node-http-proxy/routing-proxy.js index 58ed244..25026a2 100644 --- a/lib/node-http-proxy/routing-proxy.js +++ b/lib/node-http-proxy/routing-proxy.js @@ -120,7 +120,7 @@ RoutingProxy.prototype.add = function (options) { 'websocket:end', 'websocket:incoming', 'websocket:outgoing' - ].forEach(function(event) { + ].forEach(function (event) { this.proxies[key].on(event, this.emit.bind(this, event)); }, this); }; diff --git a/test/core/common.js b/test/core/common.js index 0fddb00..3f584a5 100644 --- a/test/core/common.js +++ b/test/core/common.js @@ -45,7 +45,7 @@ function protoCtrChain(o) { return result.join(); } -exports.indirectInstanceOf = function(obj, cls) { +exports.indirectInstanceOf = function (obj, cls) { if (obj instanceof cls) { return true; } var clsChain = protoCtrChain(cls.prototype); var objChain = protoCtrChain(obj); @@ -53,7 +53,7 @@ exports.indirectInstanceOf = function(obj, cls) { }; -exports.ddCommand = function(filename, kilobytes) { +exports.ddCommand = function (filename, kilobytes) { if (process.platform === 'win32') { var p = path.resolve(exports.fixturesDir, 'create-file.js'); return '"' + process.argv[0] + '" "' + p + '" "' + @@ -64,7 +64,7 @@ exports.ddCommand = function(filename, kilobytes) { }; -exports.spawnPwd = function(options) { +exports.spawnPwd = function (options) { var spawn = require('child_process').spawn; if (process.platform === 'win32') { @@ -78,7 +78,7 @@ exports.spawnPwd = function(options) { // Turn this off if the test should not check for global leaks. exports.globalCheck = true; -process.on('exit', function() { +process.on('exit', function () { if (!exports.globalCheck) return; var knownGlobals = [setTimeout, setInterval, @@ -152,11 +152,11 @@ var mustCallChecks = []; function runCallChecks() { - var failed = mustCallChecks.filter(function(context) { + var failed = mustCallChecks.filter(function (context) { return context.actual !== context.expected; }); - failed.forEach(function(context) { + failed.forEach(function (context) { console.log('Mismatched %s function calls. Expected %d, actual %d.', context.name, context.expected, @@ -168,7 +168,7 @@ function runCallChecks() { } -exports.mustCall = function(fn, expected) { +exports.mustCall = function (fn, expected) { if (typeof expected !== 'number') expected = 1; var context = { @@ -183,7 +183,7 @@ exports.mustCall = function(fn, expected) { mustCallChecks.push(context); - return function() { + return function () { context.actual++; return fn.apply(this, arguments); }; diff --git a/test/core/pummel/test-http-upload-timeout.js b/test/core/pummel/test-http-upload-timeout.js index f8efe41..74b458f 100644 --- a/test/core/pummel/test-http-upload-timeout.js +++ b/test/core/pummel/test-http-upload-timeout.js @@ -28,12 +28,12 @@ var common = require('../common'), server = http.createServer(), connections = 0; -server.on('request', function(req, res) { +server.on('request', function (req, res) { req.socket.setTimeout(1000); - req.socket.on('timeout', function() { + req.socket.on('timeout', function () { throw new Error('Unexpected timeout'); }); - req.on('end', function() { + req.on('end', function () { connections--; res.writeHead(200); res.end('done\n'); @@ -43,11 +43,11 @@ server.on('request', function(req, res) { }); }); -server.listen(common.PORT, '127.0.0.1', function() { +server.listen(common.PORT, '127.0.0.1', function () { for (var i = 0; i < 10; i++) { connections++; - setTimeout(function() { + setTimeout(function () { var request = http.request({ port: common.PROXY_PORT, method: 'POST', diff --git a/test/core/simple/test-http-chunked.js b/test/core/simple/test-http-chunked.js index 8a19f57..b1cbf0d 100644 --- a/test/core/simple/test-http-chunked.js +++ b/test/core/simple/test-http-chunked.js @@ -33,23 +33,23 @@ var UTF8_STRING = '南越国是前203年至前111年存在于岭南地区的一 '采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,' + '有效的改善了岭南地区落后的政治、经济现状。'; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'}); res.end(UTF8_STRING, 'utf8'); }); -server.listen(common.PORT, function() { +server.listen(common.PORT, function () { var data = ''; var get = http.get({ path: '/', host: 'localhost', port: common.PROXY_PORT - }, function(x) { + }, function (x) { x.setEncoding('utf8'); - x.on('data', function(c) {data += c}); - x.on('error', function(e) { + x.on('data', function (c) {data += c}); + x.on('error', function (e) { throw e; }); - x.on('end', function() { + x.on('end', function () { assert.equal('string', typeof data); console.log('here is the response:'); assert.equal(UTF8_STRING, data); @@ -57,7 +57,7 @@ server.listen(common.PORT, function() { server.close(); }); }); - get.on('error', function(e) {throw e}); + get.on('error', function (e) {throw e}); get.end(); }); diff --git a/test/core/simple/test-http-client-abort.js b/test/core/simple/test-http-client-abort.js index c7a55e2..78d0a6f 100644 --- a/test/core/simple/test-http-client-abort.js +++ b/test/core/simple/test-http-client-abort.js @@ -25,7 +25,7 @@ var http = require('http'); var clientAborts = 0; -var server = http.Server(function(req, res) { +var server = http.Server(function (req, res) { console.log('Got connection'); res.writeHead(200); res.write('Working on it...'); @@ -33,7 +33,7 @@ var server = http.Server(function(req, res) { // I would expect an error event from req or res that the client aborted // before completing the HTTP request / response cycle, or maybe a new // event like "aborted" or something. - req.on('aborted', function() { + req.on('aborted', function () { clientAborts++; console.log('Got abort ' + clientAborts); if (clientAborts === N) { @@ -44,7 +44,7 @@ var server = http.Server(function(req, res) { // since there is already clientError, maybe that would be appropriate, // since "error" is magical - req.on('clientError', function() { + req.on('clientError', function () { console.log('Got clientError'); }); }); @@ -53,18 +53,18 @@ var responses = 0; var N = http.Agent.defaultMaxSockets - 1; var requests = []; -server.listen(common.PORT, function() { +server.listen(common.PORT, function () { console.log('Server listening.'); for (var i = 0; i < N; i++) { console.log('Making client ' + i); var options = { port: common.PROXY_PORT, path: '/?id=' + i }; - var req = http.get(options, function(res) { + var req = http.get(options, function (res) { console.log('Client response code ' + res.statusCode); if (++responses == N) { console.log('All clients connected, destroying.'); - requests.forEach(function(outReq) { + requests.forEach(function (outReq) { console.log('abort'); outReq.abort(); }); @@ -75,6 +75,6 @@ server.listen(common.PORT, function() { } }); -process.on('exit', function() { +process.on('exit', function () { assert.equal(N, clientAborts); }); diff --git a/test/core/simple/test-http-client-abort2.js b/test/core/simple/test-http-client-abort2.js index 41c62d9..eef05fb 100644 --- a/test/core/simple/test-http-client-abort2.js +++ b/test/core/simple/test-http-client-abort2.js @@ -26,13 +26,13 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.end('Hello'); }); -server.listen(common.PORT, function() { - var req = http.get({port: common.PROXY_PORT}, function(res) { - res.on('data', function(data) { +server.listen(common.PORT, function () { + var req = http.get({port: common.PROXY_PORT}, function (res) { + res.on('data', function (data) { req.abort(); server.close(); }); diff --git a/test/core/simple/test-http-client-upload-buf.js b/test/core/simple/test-http-client-upload-buf.js index 125aa0c..3b8e9ab 100644 --- a/test/core/simple/test-http-client-upload-buf.js +++ b/test/core/simple/test-http-client-upload-buf.js @@ -28,14 +28,14 @@ var bytesRecieved = 0; var server_req_complete = false; var client_res_complete = false; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { assert.equal('POST', req.method); - req.on('data', function(chunk) { + req.on('data', function (chunk) { bytesRecieved += chunk.length; }); - req.on('end', function() { + req.on('end', function () { server_req_complete = true; console.log('request complete from server'); res.writeHead(200, {'Content-Type': 'text/plain'}); @@ -45,17 +45,17 @@ var server = http.createServer(function(req, res) { }); server.listen(common.PORT); -server.on('listening', function() { +server.on('listening', function () { var req = http.request({ port: common.PROXY_PORT, method: 'POST', path: '/' - }, function(res) { + }, function (res) { res.setEncoding('utf8'); - res.on('data', function(chunk) { + res.on('data', function (chunk) { console.log(chunk); }); - res.on('end', function() { + res.on('end', function () { client_res_complete = true; server.close(); }); @@ -67,7 +67,7 @@ server.on('listening', function() { common.error('client finished sending request'); }); -process.on('exit', function() { +process.on('exit', function () { assert.equal(N, bytesRecieved); assert.equal(true, server_req_complete); assert.equal(true, client_res_complete); diff --git a/test/core/simple/test-http-client-upload.js b/test/core/simple/test-http-client-upload.js index fdd88ca..fef706f 100644 --- a/test/core/simple/test-http-client-upload.js +++ b/test/core/simple/test-http-client-upload.js @@ -27,16 +27,16 @@ var sent_body = ''; var server_req_complete = false; var client_res_complete = false; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { assert.equal('POST', req.method); req.setEncoding('utf8'); - req.on('data', function(chunk) { + req.on('data', function (chunk) { console.log('server got: ' + JSON.stringify(chunk)); sent_body += chunk; }); - req.on('end', function() { + req.on('end', function () { server_req_complete = true; console.log('request complete from server'); res.writeHead(200, {'Content-Type': 'text/plain'}); @@ -46,17 +46,17 @@ var server = http.createServer(function(req, res) { }); server.listen(common.PORT); -server.on('listening', function() { +server.on('listening', function () { var req = http.request({ port: common.PROXY_PORT, method: 'POST', path: '/' - }, function(res) { + }, function (res) { res.setEncoding('utf8'); - res.on('data', function(chunk) { + res.on('data', function (chunk) { console.log(chunk); }); - res.on('end', function() { + res.on('end', function () { client_res_complete = true; server.close(); }); @@ -70,7 +70,7 @@ server.on('listening', function() { common.error('client finished sending request'); }); -process.on('exit', function() { +process.on('exit', function () { assert.equal('1\n2\n3\n', sent_body); assert.equal(true, server_req_complete); assert.equal(true, client_res_complete); diff --git a/test/core/simple/test-http-contentLength0.js b/test/core/simple/test-http-contentLength0.js index 1602c02..abc3747 100644 --- a/test/core/simple/test-http-contentLength0.js +++ b/test/core/simple/test-http-contentLength0.js @@ -27,13 +27,13 @@ var http = require('http'); // I.E. a space character after the 'Content-Length' throws an `error` event. -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { res.writeHead(200, {'Content-Length': '0 '}); res.end(); }); -s.listen(common.PORT, function() { +s.listen(common.PORT, function () { - var request = http.request({ port: common.PROXY_PORT }, function(response) { + var request = http.request({ port: common.PROXY_PORT }, function (response) { console.log('STATUS: ' + response.statusCode); s.close(); }); diff --git a/test/core/simple/test-http-eof-on-connect.js b/test/core/simple/test-http-eof-on-connect.js index b043a2d..d02ee6d 100644 --- a/test/core/simple/test-http-eof-on-connect.js +++ b/test/core/simple/test-http-eof-on-connect.js @@ -28,13 +28,13 @@ var http = require('http'); // It is separate from test-http-malformed-request.js because it is only // reproduceable on the first packet on the first connection to a server. -var server = http.createServer(function(req, res) {}); +var server = http.createServer(function (req, res) {}); server.listen(common.PORT); -server.on('listening', function() { - net.createConnection(common.PROXY_PORT).on('connect', function() { +server.on('listening', function () { + net.createConnection(common.PROXY_PORT).on('connect', function () { this.destroy(); - }).on('close', function() { + }).on('close', function () { server.close(); }); }); diff --git a/test/core/simple/test-http-extra-response.js b/test/core/simple/test-http-extra-response.js index 29143d0..a3d2746 100644 --- a/test/core/simple/test-http-extra-response.js +++ b/test/core/simple/test-http-extra-response.js @@ -43,12 +43,12 @@ var fullResponse = var gotResponse = false; -var server = net.createServer(function(socket) { +var server = net.createServer(function (socket) { var postBody = ''; socket.setEncoding('utf8'); - socket.on('data', function(chunk) { + socket.on('data', function (chunk) { postBody += chunk; if (postBody.indexOf('\r\n') > -1) { @@ -60,17 +60,17 @@ var server = net.createServer(function(socket) { }); -server.listen(common.PORT, function() { - http.get({ port: common.PROXY_PORT }, function(res) { +server.listen(common.PORT, function () { + http.get({ port: common.PROXY_PORT }, function (res) { var buffer = ''; console.log('Got res code: ' + res.statusCode); res.setEncoding('utf8'); - res.on('data', function(chunk) { + res.on('data', function (chunk) { buffer += chunk; }); - res.on('end', function() { + res.on('end', function () { console.log('Response ended, read ' + buffer.length + ' bytes'); assert.equal(body, buffer); server.close(); @@ -80,7 +80,7 @@ server.listen(common.PORT, function() { }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(gotResponse); }); diff --git a/test/core/simple/test-http-head-request.js b/test/core/simple/test-http-head-request.js index 409698a..e8c203e 100644 --- a/test/core/simple/test-http-head-request.js +++ b/test/core/simple/test-http-head-request.js @@ -27,7 +27,7 @@ var util = require('util'); var body = 'hello world\n'; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { common.error('req: ' + req.method); res.writeHead(200, {'Content-Length': body.length}); res.end(); @@ -36,14 +36,14 @@ var server = http.createServer(function(req, res) { var gotEnd = false; -server.listen(common.PORT, function() { +server.listen(common.PORT, function () { var request = http.request({ port: common.PROXY_PORT, method: 'HEAD', path: '/' - }, function(response) { + }, function (response) { common.error('response start'); - response.on('end', function() { + response.on('end', function () { common.error('response end'); gotEnd = true; }); @@ -51,6 +51,6 @@ server.listen(common.PORT, function() { request.end(); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(gotEnd); }); diff --git a/test/core/simple/test-http-head-response-has-no-body-end.js b/test/core/simple/test-http-head-response-has-no-body-end.js index 9a50e5a..6d89bee 100644 --- a/test/core/simple/test-http-head-response-has-no-body-end.js +++ b/test/core/simple/test-http-head-response-has-no-body-end.js @@ -31,7 +31,7 @@ var http = require('http'); // responds to a HEAD request with data to res.end, // it does not send any body. -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200); res.end('FAIL'); // broken: sends FAIL from hot path. }); @@ -39,14 +39,14 @@ server.listen(common.PORT); var responseComplete = false; -server.on('listening', function() { +server.on('listening', function () { var req = http.request({ port: common.PROXY_PORT, method: 'HEAD', path: '/' - }, function(res) { + }, function (res) { common.error('response'); - res.on('end', function() { + res.on('end', function () { common.error('response end'); server.close(); responseComplete = true; @@ -56,6 +56,6 @@ server.on('listening', function() { req.end(); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(responseComplete); }); diff --git a/test/core/simple/test-http-head-response-has-no-body.js b/test/core/simple/test-http-head-response-has-no-body.js index 614b648..aa7a281 100644 --- a/test/core/simple/test-http-head-response-has-no-body.js +++ b/test/core/simple/test-http-head-response-has-no-body.js @@ -28,7 +28,7 @@ var http = require('http'); // responds to a HEAD request, it does not send any body. // In this case it was sending '0\r\n\r\n' -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200); // broken: defaults to TE chunked res.end(); }); @@ -36,14 +36,14 @@ server.listen(common.PORT); var responseComplete = false; -server.on('listening', function() { +server.on('listening', function () { var req = http.request({ port: common.PROXY_PORT, method: 'HEAD', path: '/' - }, function(res) { + }, function (res) { common.error('response'); - res.on('end', function() { + res.on('end', function () { common.error('response end'); server.close(); responseComplete = true; @@ -53,6 +53,6 @@ server.on('listening', function() { req.end(); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(responseComplete); }); diff --git a/test/core/simple/test-http-host-headers.js b/test/core/simple/test-http-host-headers.js index bb0957e..2dae118 100644 --- a/test/core/simple/test-http-host-headers.js +++ b/test/core/simple/test-http-host-headers.js @@ -37,7 +37,7 @@ function reqHandler(req, res) { req.headers.host); } res.writeHead(200, {}); - //process.nextTick(function() { res.end('ok'); }); + //process.nextTick(function () { res.end('ok'); }); res.end('ok'); } @@ -62,7 +62,7 @@ function testHttp() { } } - httpServer.listen(common.PORT, function(er) { + httpServer.listen(common.PORT, function (er) { console.error('listening on ' + common.PORT); if (er) throw er; diff --git a/test/core/simple/test-http-many-keep-alive-connections.js b/test/core/simple/test-http-many-keep-alive-connections.js index 7b14ff0..6b79619 100644 --- a/test/core/simple/test-http-many-keep-alive-connections.js +++ b/test/core/simple/test-http-many-keep-alive-connections.js @@ -28,18 +28,18 @@ var responses = 0; var requests = 0; var connection; -var server = http.Server(function(req, res) { +var server = http.Server(function (req, res) { requests++; assert.equal(req.connection, connection); res.writeHead(200); res.end('hello world\n'); }); -server.once('connection', function(c) { +server.once('connection', function (c) { connection = c; }); -server.listen(common.PORT, function() { +server.listen(common.PORT, function () { var callee = arguments.callee; var request = http.get({ port: common.PROXY_PORT, @@ -47,22 +47,22 @@ server.listen(common.PORT, function() { headers: { 'Connection': 'Keep-alive' } - }, function(res) { - res.on('end', function() { + }, function (res) { + res.on('end', function () { if (++responses < expected) { callee(); } else { process.exit(); } }); - }).on('error', function(e) { + }).on('error', function (e) { console.log(e.message); process.exit(1); }); request.agent.maxSockets = 1; }); -process.on('exit', function() { +process.on('exit', function () { assert.equal(expected, responses); assert.equal(expected, requests); }); diff --git a/test/core/simple/test-http-multi-line-headers.js b/test/core/simple/test-http-multi-line-headers.js index aa00a76..e0eeb2c 100644 --- a/test/core/simple/test-http-multi-line-headers.js +++ b/test/core/simple/test-http-multi-line-headers.js @@ -27,7 +27,7 @@ var net = require('net'); var gotResponse = false; -var server = net.createServer(function(conn) { +var server = net.createServer(function (conn) { var body = 'Yet another node.js server.'; var response = @@ -40,20 +40,20 @@ var server = net.createServer(function(conn) { '\r\n' + body; - conn.write(response, function() { + conn.write(response, function () { conn.destroy(); server.close(); }); }); -server.listen(common.PORT, function() { - http.get({host: '127.0.0.1', port: common.PROXY_PORT}, function(res) { +server.listen(common.PORT, function () { + http.get({host: '127.0.0.1', port: common.PROXY_PORT}, function (res) { assert.equal(res.headers['content-type'], 'text/plain;x-unix-mode=0600;name="hello.txt"'); gotResponse = true; }); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(gotResponse); }); diff --git a/test/core/simple/test-http-proxy.js b/test/core/simple/test-http-proxy.js index 2bbf9be..fdddb3c 100644 --- a/test/core/simple/test-http-proxy.js +++ b/test/core/simple/test-http-proxy.js @@ -36,19 +36,19 @@ var headers = {'content-type': 'text/plain', 'set-cookie': cookies, 'hello': 'world' }; -var backend = http.createServer(function(req, res) { +var backend = http.createServer(function (req, res) { common.debug('backend request'); res.writeHead(200, headers); res.write('hello world\n'); res.end(); }); -var proxy = http.createServer(function(req, res) { +var proxy = http.createServer(function (req, res) { common.debug('proxy req headers: ' + JSON.stringify(req.headers)); var proxy_req = http.get({ port: BACKEND_PORT, path: url.parse(req.url).pathname - }, function(proxy_res) { + }, function (proxy_res) { common.debug('proxy res headers: ' + JSON.stringify(proxy_res.headers)); @@ -58,11 +58,11 @@ var proxy = http.createServer(function(req, res) { res.writeHead(proxy_res.statusCode, proxy_res.headers); - proxy_res.on('data', function(chunk) { + proxy_res.on('data', function (chunk) { res.write(chunk); }); - proxy_res.on('end', function() { + proxy_res.on('end', function () { res.end(); common.debug('proxy res'); }); @@ -79,7 +79,7 @@ function startReq() { var client = http.get({ port: common.PROXY_PORT, path: '/test' - }, function(res) { + }, function (res) { common.debug('got res'); assert.equal(200, res.statusCode); @@ -88,8 +88,8 @@ function startReq() { assert.deepEqual(cookies, res.headers['set-cookie']); res.setEncoding('utf8'); - res.on('data', function(chunk) { body += chunk; }); - res.on('end', function() { + res.on('data', function (chunk) { body += chunk; }); + res.on('end', function () { proxy.close(); backend.close(); common.debug('closed both'); @@ -104,6 +104,6 @@ proxy.listen(PROXY_PORT, startReq); common.debug('listen backend'); backend.listen(BACKEND_PORT, startReq); -process.on('exit', function() { +process.on('exit', function () { assert.equal(body, 'hello world\n'); }); diff --git a/test/core/simple/test-http-response-close.js b/test/core/simple/test-http-response-close.js index d4adf80..b92abb0 100644 --- a/test/core/simple/test-http-response-close.js +++ b/test/core/simple/test-http-response-close.js @@ -25,24 +25,24 @@ var http = require('http'); var gotEnd = false; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { res.writeHead(200); res.write('a'); - req.on('close', function() { + req.on('close', function () { console.error('aborted'); gotEnd = true; }); }); server.listen(common.PORT); -server.on('listening', function() { +server.on('listening', function () { console.error('make req'); http.get({ port: common.PROXY_PORT - }, function(res) { + }, function (res) { console.error('got res'); - res.on('data', function(data) { + res.on('data', function (data) { console.error('destroy res'); res.destroy(); server.close(); @@ -50,6 +50,6 @@ server.on('listening', function() { }); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(gotEnd); }); diff --git a/test/core/simple/test-http-server-multiheaders.js b/test/core/simple/test-http-server-multiheaders.js index 52b932f..6a5b8be 100644 --- a/test/core/simple/test-http-server-multiheaders.js +++ b/test/core/simple/test-http-server-multiheaders.js @@ -27,7 +27,7 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); -var srv = http.createServer(function(req, res) { +var srv = http.createServer(function (req, res) { assert.equal(req.headers.accept, 'abc, def, ghijklmnopqrst'); assert.equal(req.headers.host, 'foo'); assert.equal(req.headers['x-foo'], 'bingo'); @@ -39,7 +39,7 @@ var srv = http.createServer(function(req, res) { srv.close(); }); -srv.listen(common.PORT, function() { +srv.listen(common.PORT, function () { http.get({ host: 'localhost', port: common.PROXY_PORT, diff --git a/test/core/simple/test-http-set-cookies.js b/test/core/simple/test-http-set-cookies.js index 9510e49..aac2994 100644 --- a/test/core/simple/test-http-set-cookies.js +++ b/test/core/simple/test-http-set-cookies.js @@ -25,7 +25,7 @@ var http = require('http'); var nresponses = 0; -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { if (req.url == '/one') { res.writeHead(200, [['set-cookie', 'A'], ['content-type', 'text/plain']]); @@ -39,21 +39,21 @@ var server = http.createServer(function(req, res) { }); server.listen(common.PORT); -server.on('listening', function() { +server.on('listening', function () { // // one set-cookie header // - http.get({ port: common.PROXY_PORT, path: '/one' }, function(res) { + http.get({ port: common.PROXY_PORT, path: '/one' }, function (res) { // set-cookie headers are always return in an array. // even if there is only one. assert.deepEqual(['A'], res.headers['set-cookie']); assert.equal('text/plain', res.headers['content-type']); - res.on('data', function(chunk) { + res.on('data', function (chunk) { console.log(chunk.toString()); }); - res.on('end', function() { + res.on('end', function () { if (++nresponses == 2) { server.close(); } @@ -62,15 +62,15 @@ server.on('listening', function() { // two set-cookie headers - http.get({ port: common.PROXY_PORT, path: '/two' }, function(res) { + http.get({ port: common.PROXY_PORT, path: '/two' }, function (res) { assert.deepEqual(['A', 'B'], res.headers['set-cookie']); assert.equal('text/plain', res.headers['content-type']); - res.on('data', function(chunk) { + res.on('data', function (chunk) { console.log(chunk.toString()); }); - res.on('end', function() { + res.on('end', function () { if (++nresponses == 2) { server.close(); } @@ -79,6 +79,6 @@ server.on('listening', function() { }); -process.on('exit', function() { +process.on('exit', function () { assert.equal(2, nresponses); }); diff --git a/test/core/simple/test-http-status-code.js b/test/core/simple/test-http-status-code.js index b79e4d7..dffbaf7 100644 --- a/test/core/simple/test-http-status-code.js +++ b/test/core/simple/test-http-status-code.js @@ -33,7 +33,7 @@ var testsComplete = 0; var tests = [200, 202, 300, 404, 500]; var testIdx = 0; -var s = http.createServer(function(req, res) { +var s = http.createServer(function (req, res) { var t = tests[testIdx]; res.writeHead(t, {'Content-Type': 'text/plain'}); console.log('--\nserver: statusCode after writeHead: ' + res.statusCode); @@ -50,11 +50,11 @@ function nextTest() { } var test = tests[testIdx]; - http.get({ port: common.PROXY_PORT }, function(response) { + http.get({ port: common.PROXY_PORT }, function (response) { console.log('client: expected status: ' + test); console.log('client: statusCode: ' + response.statusCode); assert.equal(response.statusCode, test); - response.on('end', function() { + response.on('end', function () { testsComplete++; testIdx += 1; nextTest(); @@ -63,7 +63,7 @@ function nextTest() { } -process.on('exit', function() { +process.on('exit', function () { assert.equal(4, testsComplete); }); diff --git a/test/core/simple/test-http-upgrade-server2.js b/test/core/simple/test-http-upgrade-server2.js index 8825f97..a527376 100644 --- a/test/core/simple/test-http-upgrade-server2.js +++ b/test/core/simple/test-http-upgrade-server2.js @@ -24,12 +24,12 @@ var assert = require('assert'); var http = require('http'); var net = require('net'); -var server = http.createServer(function(req, res) { +var server = http.createServer(function (req, res) { common.error('got req'); throw new Error('This shouldn\'t happen.'); }); -server.on('upgrade', function(req, socket, upgradeHead) { +server.on('upgrade', function (req, socket, upgradeHead) { common.error('got upgrade event'); // test that throwing an error from upgrade gets // is uncaught @@ -38,7 +38,7 @@ server.on('upgrade', function(req, socket, upgradeHead) { var gotError = false; -process.on('uncaughtException', function(e) { +process.on('uncaughtException', function (e) { common.error('got \'clientError\' event'); assert.equal('upgrade error', e.message); gotError = true; @@ -46,10 +46,10 @@ process.on('uncaughtException', function(e) { }); -server.listen(common.PORT, function() { +server.listen(common.PORT, function () { var c = net.createConnection(common.PROXY_PORT); - c.on('connect', function() { + c.on('connect', function () { common.error('client wrote message'); c.write('GET /blah HTTP/1.1\r\n' + 'Upgrade: WebSocket\r\n' + @@ -57,16 +57,16 @@ server.listen(common.PORT, function() { '\r\n\r\nhello world'); }); - c.on('end', function() { + c.on('end', function () { c.end(); }); - c.on('close', function() { + c.on('close', function () { common.error('client close'); server.close(); }); }); -process.on('exit', function() { +process.on('exit', function () { assert.ok(gotError); }); diff --git a/test/core/simple/test-http.js b/test/core/simple/test-http.js index fcbec28..e082eb2 100644 --- a/test/core/simple/test-http.js +++ b/test/core/simple/test-http.js @@ -33,7 +33,7 @@ var responses_recvd = 0; var body0 = ''; var body1 = ''; -var server = http.Server(function(req, res) { +var server = http.Server(function (req, res) { if (responses_sent == 0) { assert.equal('GET', req.method); assert.equal('/hello', url.parse(req.url).pathname); @@ -52,7 +52,7 @@ var server = http.Server(function(req, res) { this.close(); } - req.on('end', function() { + req.on('end', function () { res.writeHead(200, {'Content-Type': 'text/plain'}); res.write('The path was ' + url.parse(req.url).pathname); res.end(); @@ -63,39 +63,39 @@ var server = http.Server(function(req, res) { }); server.listen(common.PORT); -server.on('listening', function() { +server.on('listening', function () { var agent = new http.Agent({ port: common.PROXY_PORT, maxSockets: 1 }); http.get({ port: common.PROXY_PORT, path: '/hello', headers: {'Accept': '*/*', 'Foo': 'bar'}, agent: agent - }, function(res) { + }, function (res) { assert.equal(200, res.statusCode); responses_recvd += 1; res.setEncoding('utf8'); - res.on('data', function(chunk) { body0 += chunk; }); + res.on('data', function (chunk) { body0 += chunk; }); common.debug('Got /hello response'); }); - setTimeout(function() { + setTimeout(function () { var req = http.request({ port: common.PROXY_PORT, method: 'POST', path: '/world', agent: agent - }, function(res) { + }, function (res) { assert.equal(200, res.statusCode); responses_recvd += 1; res.setEncoding('utf8'); - res.on('data', function(chunk) { body1 += chunk; }); + res.on('data', function (chunk) { body1 += chunk; }); common.debug('Got /world response'); }); req.end(); }, 1); }); -process.on('exit', function() { +process.on('exit', function () { common.debug('responses_recvd: ' + responses_recvd); assert.equal(2, responses_recvd); diff --git a/test/helpers/http.js b/test/helpers/http.js index fb4abf4..24749be 100644 --- a/test/helpers/http.js +++ b/test/helpers/http.js @@ -61,8 +61,8 @@ exports.createServer = function (options, callback) { }); } - if (options.outputHeaders){ - Object.keys(options.outputHeaders).forEach(function(header){ + if (options.outputHeaders) { + Object.keys(options.outputHeaders).forEach(function (header) { res.setHeader(header, options.outputHeaders[header]); }); } @@ -120,8 +120,8 @@ exports.createProxyServer = function (options, callback) { function requestHandler(req, res) { var buffer = httpProxy.buffer(req); - if (options.outputHeaders){ - Object.keys(options.outputHeaders).forEach(function(header){ + if (options.outputHeaders) { + Object.keys(options.outputHeaders).forEach(function (header) { res.setHeader(header, options.outputHeaders[header]); }); }