[minor] s/function(/function (/ s/){/) {/

This commit is contained in:
indexzero 2013-03-09 01:43:25 -05:00
parent 440013c263
commit 9cecd97153
32 changed files with 163 additions and 163 deletions

View File

@ -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
//

View File

@ -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);
});

View File

@ -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 {

View File

@ -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',

View File

@ -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',

View File

@ -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);
// });
//

View File

@ -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();
}

View File

@ -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);
};

View File

@ -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);
};

View File

@ -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',

View File

@ -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();
});

View File

@ -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);
});

View File

@ -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();
});

View File

@ -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);

View File

@ -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);

View File

@ -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();
});

View File

@ -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();
});
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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;

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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');
});

View File

@ -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);
});

View File

@ -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,

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);
});

View File

@ -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);

View File

@ -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]);
});
}