mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[minor] s/function(/function (/ s/){/) {/
This commit is contained in:
parent
440013c263
commit
9cecd97153
12
README.md
12
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.");
|
console.log("The request was proxied.");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ var certs = {
|
|||||||
//
|
//
|
||||||
var options = {
|
var options = {
|
||||||
https: {
|
https: {
|
||||||
SNICallback: function(hostname){
|
SNICallback: function (hostname) {
|
||||||
return certs[hostname];
|
return certs[hostname];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -424,8 +424,8 @@ var server = httpProxy.createServer(
|
|||||||
options
|
options
|
||||||
);
|
);
|
||||||
|
|
||||||
server.listen(port, function() { ... });
|
server.listen(port, function () { ... });
|
||||||
server.on('upgrade', function(req, socket, head) {
|
server.on('upgrade', function (req, socket, head) {
|
||||||
server.proxy.proxyWebSocketRequest(req, socket, head);
|
server.proxy.proxyWebSocketRequest(req, socket, head);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@ -453,7 +453,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
proxy.proxyRequest(req, res);
|
proxy.proxyRequest(req, res);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.on('upgrade', function(req, socket, head) {
|
server.on('upgrade', function (req, socket, head) {
|
||||||
//
|
//
|
||||||
// Proxy websocket requests too
|
// 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
|
// Put your custom server logic here
|
||||||
//
|
//
|
||||||
|
|||||||
@ -50,7 +50,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
// Get the 'next' proxy and send the upgrade request
|
// 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);
|
nextProxy().proxyWebSocketRequest(req, socket, head);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -39,10 +39,10 @@ Store.prototype = {
|
|||||||
res.end()
|
res.end()
|
||||||
}
|
}
|
||||||
var url = req.url.split('?').shift()
|
var url = req.url.split('?').shift()
|
||||||
if(url === '/') {
|
if (url === '/') {
|
||||||
console.log('get index')
|
console.log('get index')
|
||||||
return send(Object.keys(store.store))
|
return send(Object.keys(store.store))
|
||||||
} else if(req.method == 'GET') {
|
} else if (req.method == 'GET') {
|
||||||
var obj = store.get (url)
|
var obj = store.get (url)
|
||||||
send(obj || {error: 'not_found', url: url}, obj ? 200 : 404)
|
send(obj || {error: 'not_found', url: url}, obj ? 200 : 404)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ var util = require('util'),
|
|||||||
//
|
//
|
||||||
httpProxy.createServer(function (req, res, proxy) {
|
httpProxy.createServer(function (req, res, proxy) {
|
||||||
var buffer = httpProxy.buffer(req);
|
var buffer = httpProxy.buffer(req);
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
proxy.proxyRequest(req, res, {
|
proxy.proxyRequest(req, res, {
|
||||||
port: 9000,
|
port: 9000,
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
|
|||||||
@ -35,7 +35,7 @@ var util = require('util'),
|
|||||||
var proxy = new httpProxy.RoutingProxy();
|
var proxy = new httpProxy.RoutingProxy();
|
||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
var buffer = httpProxy.buffer(req);
|
var buffer = httpProxy.buffer(req);
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
proxy.proxyRequest(req, res, {
|
proxy.proxyRequest(req, res, {
|
||||||
port: 9000,
|
port: 9000,
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
|
|||||||
@ -211,7 +211,7 @@ exports.createServer = function () {
|
|||||||
// __events will be lost.__
|
// __events will be lost.__
|
||||||
//
|
//
|
||||||
// var buffer = httpProxy.buffer(req);
|
// var buffer = httpProxy.buffer(req);
|
||||||
// fs.readFile(path, function(){
|
// fs.readFile(path, function () {
|
||||||
// httpProxy.proxyRequest(req, res, host, port, buffer);
|
// httpProxy.proxyRequest(req, res, host, port, buffer);
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
|
|||||||
@ -134,7 +134,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
// * `x-forwarded-port`: Port of the original request.
|
// * `x-forwarded-port`: Port of the original request.
|
||||||
//
|
//
|
||||||
if (this.enable.xforward && req.connection && req.socket) {
|
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;
|
var addressToAppend = "," + req.connection.remoteAddress || req.socket.remoteAddress;
|
||||||
req.headers['x-forwarded-for'] += addressToAppend;
|
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;
|
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;
|
var portToAppend = "," + req.connection.remotePort || req.socket.remotePort;
|
||||||
req.headers['x-forwarded-port'] += portToAppend;
|
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;
|
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);
|
var protoToAppend = "," + getProto(req);
|
||||||
req.headers['x-forwarded-proto'] += protoToAppend;
|
req.headers['x-forwarded-proto'] += protoToAppend;
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Set the headers of the client response
|
// 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.setHeader(key, response.headers[key]);
|
||||||
});
|
});
|
||||||
res.writeHead(response.statusCode);
|
res.writeHead(response.statusCode);
|
||||||
@ -438,7 +438,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
|
|||||||
// * `x-forwarded-port`: Port of the original request.
|
// * `x-forwarded-port`: Port of the original request.
|
||||||
//
|
//
|
||||||
if (this.enable.xforward && req.connection) {
|
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;
|
var addressToAppend = "," + req.connection.remoteAddress || socket.remoteAddress;
|
||||||
req.headers['x-forwarded-for'] += addressToAppend;
|
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;
|
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;
|
var portToAppend = "," + req.connection.remotePort || socket.remotePort;
|
||||||
req.headers['x-forwarded-port'] += portToAppend;
|
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;
|
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');
|
var protoToAppend = "," + (req.connection.pair ? 'wss' : 'ws');
|
||||||
req.headers['x-forwarded-proto'] += protoToAppend;
|
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
|
// If the incoming `proxySocket` socket closes, then
|
||||||
// detach all event listeners.
|
// detach all event listeners.
|
||||||
//
|
//
|
||||||
listeners.onIncomingClose = function() {
|
listeners.onIncomingClose = function () {
|
||||||
reverseProxy.incoming.socket.destroy();
|
reverseProxy.incoming.socket.destroy();
|
||||||
detach();
|
detach();
|
||||||
|
|
||||||
@ -589,7 +589,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
|
|||||||
// If the `reverseProxy` socket closes, then detach all
|
// If the `reverseProxy` socket closes, then detach all
|
||||||
// event listeners.
|
// event listeners.
|
||||||
//
|
//
|
||||||
listeners.onOutgoingClose = function() {
|
listeners.onOutgoingClose = function () {
|
||||||
proxySocket.destroy();
|
proxySocket.destroy();
|
||||||
detach();
|
detach();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,7 +120,7 @@ RoutingProxy.prototype.add = function (options) {
|
|||||||
'websocket:end',
|
'websocket:end',
|
||||||
'websocket:incoming',
|
'websocket:incoming',
|
||||||
'websocket:outgoing'
|
'websocket:outgoing'
|
||||||
].forEach(function(event) {
|
].forEach(function (event) {
|
||||||
this.proxies[key].on(event, this.emit.bind(this, event));
|
this.proxies[key].on(event, this.emit.bind(this, event));
|
||||||
}, this);
|
}, this);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -45,7 +45,7 @@ function protoCtrChain(o) {
|
|||||||
return result.join();
|
return result.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.indirectInstanceOf = function(obj, cls) {
|
exports.indirectInstanceOf = function (obj, cls) {
|
||||||
if (obj instanceof cls) { return true; }
|
if (obj instanceof cls) { return true; }
|
||||||
var clsChain = protoCtrChain(cls.prototype);
|
var clsChain = protoCtrChain(cls.prototype);
|
||||||
var objChain = protoCtrChain(obj);
|
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') {
|
if (process.platform === 'win32') {
|
||||||
var p = path.resolve(exports.fixturesDir, 'create-file.js');
|
var p = path.resolve(exports.fixturesDir, 'create-file.js');
|
||||||
return '"' + process.argv[0] + '" "' + p + '" "' +
|
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;
|
var spawn = require('child_process').spawn;
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
@ -78,7 +78,7 @@ exports.spawnPwd = function(options) {
|
|||||||
// Turn this off if the test should not check for global leaks.
|
// Turn this off if the test should not check for global leaks.
|
||||||
exports.globalCheck = true;
|
exports.globalCheck = true;
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
if (!exports.globalCheck) return;
|
if (!exports.globalCheck) return;
|
||||||
var knownGlobals = [setTimeout,
|
var knownGlobals = [setTimeout,
|
||||||
setInterval,
|
setInterval,
|
||||||
@ -152,11 +152,11 @@ var mustCallChecks = [];
|
|||||||
|
|
||||||
|
|
||||||
function runCallChecks() {
|
function runCallChecks() {
|
||||||
var failed = mustCallChecks.filter(function(context) {
|
var failed = mustCallChecks.filter(function (context) {
|
||||||
return context.actual !== context.expected;
|
return context.actual !== context.expected;
|
||||||
});
|
});
|
||||||
|
|
||||||
failed.forEach(function(context) {
|
failed.forEach(function (context) {
|
||||||
console.log('Mismatched %s function calls. Expected %d, actual %d.',
|
console.log('Mismatched %s function calls. Expected %d, actual %d.',
|
||||||
context.name,
|
context.name,
|
||||||
context.expected,
|
context.expected,
|
||||||
@ -168,7 +168,7 @@ function runCallChecks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
exports.mustCall = function(fn, expected) {
|
exports.mustCall = function (fn, expected) {
|
||||||
if (typeof expected !== 'number') expected = 1;
|
if (typeof expected !== 'number') expected = 1;
|
||||||
|
|
||||||
var context = {
|
var context = {
|
||||||
@ -183,7 +183,7 @@ exports.mustCall = function(fn, expected) {
|
|||||||
|
|
||||||
mustCallChecks.push(context);
|
mustCallChecks.push(context);
|
||||||
|
|
||||||
return function() {
|
return function () {
|
||||||
context.actual++;
|
context.actual++;
|
||||||
return fn.apply(this, arguments);
|
return fn.apply(this, arguments);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,12 +28,12 @@ var common = require('../common'),
|
|||||||
server = http.createServer(),
|
server = http.createServer(),
|
||||||
connections = 0;
|
connections = 0;
|
||||||
|
|
||||||
server.on('request', function(req, res) {
|
server.on('request', function (req, res) {
|
||||||
req.socket.setTimeout(1000);
|
req.socket.setTimeout(1000);
|
||||||
req.socket.on('timeout', function() {
|
req.socket.on('timeout', function () {
|
||||||
throw new Error('Unexpected timeout');
|
throw new Error('Unexpected timeout');
|
||||||
});
|
});
|
||||||
req.on('end', function() {
|
req.on('end', function () {
|
||||||
connections--;
|
connections--;
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end('done\n');
|
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++) {
|
for (var i = 0; i < 10; i++) {
|
||||||
connections++;
|
connections++;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
var request = http.request({
|
var request = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
@ -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.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
|
||||||
res.end(UTF8_STRING, 'utf8');
|
res.end(UTF8_STRING, 'utf8');
|
||||||
});
|
});
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
var data = '';
|
var data = '';
|
||||||
var get = http.get({
|
var get = http.get({
|
||||||
path: '/',
|
path: '/',
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: common.PROXY_PORT
|
port: common.PROXY_PORT
|
||||||
}, function(x) {
|
}, function (x) {
|
||||||
x.setEncoding('utf8');
|
x.setEncoding('utf8');
|
||||||
x.on('data', function(c) {data += c});
|
x.on('data', function (c) {data += c});
|
||||||
x.on('error', function(e) {
|
x.on('error', function (e) {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
x.on('end', function() {
|
x.on('end', function () {
|
||||||
assert.equal('string', typeof data);
|
assert.equal('string', typeof data);
|
||||||
console.log('here is the response:');
|
console.log('here is the response:');
|
||||||
assert.equal(UTF8_STRING, data);
|
assert.equal(UTF8_STRING, data);
|
||||||
@ -57,7 +57,7 @@ server.listen(common.PORT, function() {
|
|||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
get.on('error', function(e) {throw e});
|
get.on('error', function (e) {throw e});
|
||||||
get.end();
|
get.end();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,7 +25,7 @@ var http = require('http');
|
|||||||
|
|
||||||
var clientAborts = 0;
|
var clientAborts = 0;
|
||||||
|
|
||||||
var server = http.Server(function(req, res) {
|
var server = http.Server(function (req, res) {
|
||||||
console.log('Got connection');
|
console.log('Got connection');
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.write('Working on it...');
|
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
|
// 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
|
// before completing the HTTP request / response cycle, or maybe a new
|
||||||
// event like "aborted" or something.
|
// event like "aborted" or something.
|
||||||
req.on('aborted', function() {
|
req.on('aborted', function () {
|
||||||
clientAborts++;
|
clientAborts++;
|
||||||
console.log('Got abort ' + clientAborts);
|
console.log('Got abort ' + clientAborts);
|
||||||
if (clientAborts === N) {
|
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 there is already clientError, maybe that would be appropriate,
|
||||||
// since "error" is magical
|
// since "error" is magical
|
||||||
req.on('clientError', function() {
|
req.on('clientError', function () {
|
||||||
console.log('Got clientError');
|
console.log('Got clientError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -53,18 +53,18 @@ var responses = 0;
|
|||||||
var N = http.Agent.defaultMaxSockets - 1;
|
var N = http.Agent.defaultMaxSockets - 1;
|
||||||
var requests = [];
|
var requests = [];
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
console.log('Server listening.');
|
console.log('Server listening.');
|
||||||
|
|
||||||
for (var i = 0; i < N; i++) {
|
for (var i = 0; i < N; i++) {
|
||||||
console.log('Making client ' + i);
|
console.log('Making client ' + i);
|
||||||
var options = { port: common.PROXY_PORT, path: '/?id=' + 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);
|
console.log('Client response code ' + res.statusCode);
|
||||||
|
|
||||||
if (++responses == N) {
|
if (++responses == N) {
|
||||||
console.log('All clients connected, destroying.');
|
console.log('All clients connected, destroying.');
|
||||||
requests.forEach(function(outReq) {
|
requests.forEach(function (outReq) {
|
||||||
console.log('abort');
|
console.log('abort');
|
||||||
outReq.abort();
|
outReq.abort();
|
||||||
});
|
});
|
||||||
@ -75,6 +75,6 @@ server.listen(common.PORT, function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(N, clientAborts);
|
assert.equal(N, clientAborts);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -26,13 +26,13 @@ var common = require('../common');
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
res.end('Hello');
|
res.end('Hello');
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
var req = http.get({port: common.PROXY_PORT}, function(res) {
|
var req = http.get({port: common.PROXY_PORT}, function (res) {
|
||||||
res.on('data', function(data) {
|
res.on('data', function (data) {
|
||||||
req.abort();
|
req.abort();
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,14 +28,14 @@ var bytesRecieved = 0;
|
|||||||
var server_req_complete = false;
|
var server_req_complete = false;
|
||||||
var client_res_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);
|
assert.equal('POST', req.method);
|
||||||
|
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function (chunk) {
|
||||||
bytesRecieved += chunk.length;
|
bytesRecieved += chunk.length;
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('end', function() {
|
req.on('end', function () {
|
||||||
server_req_complete = true;
|
server_req_complete = true;
|
||||||
console.log('request complete from server');
|
console.log('request complete from server');
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
@ -45,17 +45,17 @@ var server = http.createServer(function(req, res) {
|
|||||||
});
|
});
|
||||||
server.listen(common.PORT);
|
server.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
var req = http.request({
|
var req = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function (chunk) {
|
||||||
console.log(chunk);
|
console.log(chunk);
|
||||||
});
|
});
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
client_res_complete = true;
|
client_res_complete = true;
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
@ -67,7 +67,7 @@ server.on('listening', function() {
|
|||||||
common.error('client finished sending request');
|
common.error('client finished sending request');
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(N, bytesRecieved);
|
assert.equal(N, bytesRecieved);
|
||||||
assert.equal(true, server_req_complete);
|
assert.equal(true, server_req_complete);
|
||||||
assert.equal(true, client_res_complete);
|
assert.equal(true, client_res_complete);
|
||||||
|
|||||||
@ -27,16 +27,16 @@ var sent_body = '';
|
|||||||
var server_req_complete = false;
|
var server_req_complete = false;
|
||||||
var client_res_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);
|
assert.equal('POST', req.method);
|
||||||
req.setEncoding('utf8');
|
req.setEncoding('utf8');
|
||||||
|
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function (chunk) {
|
||||||
console.log('server got: ' + JSON.stringify(chunk));
|
console.log('server got: ' + JSON.stringify(chunk));
|
||||||
sent_body += chunk;
|
sent_body += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('end', function() {
|
req.on('end', function () {
|
||||||
server_req_complete = true;
|
server_req_complete = true;
|
||||||
console.log('request complete from server');
|
console.log('request complete from server');
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
@ -46,17 +46,17 @@ var server = http.createServer(function(req, res) {
|
|||||||
});
|
});
|
||||||
server.listen(common.PORT);
|
server.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
var req = http.request({
|
var req = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function (chunk) {
|
||||||
console.log(chunk);
|
console.log(chunk);
|
||||||
});
|
});
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
client_res_complete = true;
|
client_res_complete = true;
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
@ -70,7 +70,7 @@ server.on('listening', function() {
|
|||||||
common.error('client finished sending request');
|
common.error('client finished sending request');
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal('1\n2\n3\n', sent_body);
|
assert.equal('1\n2\n3\n', sent_body);
|
||||||
assert.equal(true, server_req_complete);
|
assert.equal(true, server_req_complete);
|
||||||
assert.equal(true, client_res_complete);
|
assert.equal(true, client_res_complete);
|
||||||
|
|||||||
@ -27,13 +27,13 @@ var http = require('http');
|
|||||||
// I.E. a space character after the 'Content-Length' throws an `error` event.
|
// 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.writeHead(200, {'Content-Length': '0 '});
|
||||||
res.end();
|
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);
|
console.log('STATUS: ' + response.statusCode);
|
||||||
s.close();
|
s.close();
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,13 +28,13 @@ var http = require('http');
|
|||||||
// It is separate from test-http-malformed-request.js because it is only
|
// 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.
|
// 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.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
net.createConnection(common.PROXY_PORT).on('connect', function() {
|
net.createConnection(common.PROXY_PORT).on('connect', function () {
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}).on('close', function() {
|
}).on('close', function () {
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -43,12 +43,12 @@ var fullResponse =
|
|||||||
var gotResponse = false;
|
var gotResponse = false;
|
||||||
|
|
||||||
|
|
||||||
var server = net.createServer(function(socket) {
|
var server = net.createServer(function (socket) {
|
||||||
var postBody = '';
|
var postBody = '';
|
||||||
|
|
||||||
socket.setEncoding('utf8');
|
socket.setEncoding('utf8');
|
||||||
|
|
||||||
socket.on('data', function(chunk) {
|
socket.on('data', function (chunk) {
|
||||||
postBody += chunk;
|
postBody += chunk;
|
||||||
|
|
||||||
if (postBody.indexOf('\r\n') > -1) {
|
if (postBody.indexOf('\r\n') > -1) {
|
||||||
@ -60,17 +60,17 @@ var server = net.createServer(function(socket) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
http.get({ port: common.PROXY_PORT }, function(res) {
|
http.get({ port: common.PROXY_PORT }, function (res) {
|
||||||
var buffer = '';
|
var buffer = '';
|
||||||
console.log('Got res code: ' + res.statusCode);
|
console.log('Got res code: ' + res.statusCode);
|
||||||
|
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function (chunk) {
|
||||||
buffer += chunk;
|
buffer += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
console.log('Response ended, read ' + buffer.length + ' bytes');
|
console.log('Response ended, read ' + buffer.length + ' bytes');
|
||||||
assert.equal(body, buffer);
|
assert.equal(body, buffer);
|
||||||
server.close();
|
server.close();
|
||||||
@ -80,7 +80,7 @@ server.listen(common.PORT, function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(gotResponse);
|
assert.ok(gotResponse);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,7 @@ var util = require('util');
|
|||||||
|
|
||||||
var body = 'hello world\n';
|
var body = 'hello world\n';
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
common.error('req: ' + req.method);
|
common.error('req: ' + req.method);
|
||||||
res.writeHead(200, {'Content-Length': body.length});
|
res.writeHead(200, {'Content-Length': body.length});
|
||||||
res.end();
|
res.end();
|
||||||
@ -36,14 +36,14 @@ var server = http.createServer(function(req, res) {
|
|||||||
|
|
||||||
var gotEnd = false;
|
var gotEnd = false;
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
var request = http.request({
|
var request = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(response) {
|
}, function (response) {
|
||||||
common.error('response start');
|
common.error('response start');
|
||||||
response.on('end', function() {
|
response.on('end', function () {
|
||||||
common.error('response end');
|
common.error('response end');
|
||||||
gotEnd = true;
|
gotEnd = true;
|
||||||
});
|
});
|
||||||
@ -51,6 +51,6 @@ server.listen(common.PORT, function() {
|
|||||||
request.end();
|
request.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(gotEnd);
|
assert.ok(gotEnd);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -31,7 +31,7 @@ var http = require('http');
|
|||||||
// responds to a HEAD request with data to res.end,
|
// responds to a HEAD request with data to res.end,
|
||||||
// it does not send any body.
|
// it does not send any body.
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end('FAIL'); // broken: sends FAIL from hot path.
|
res.end('FAIL'); // broken: sends FAIL from hot path.
|
||||||
});
|
});
|
||||||
@ -39,14 +39,14 @@ server.listen(common.PORT);
|
|||||||
|
|
||||||
var responseComplete = false;
|
var responseComplete = false;
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
var req = http.request({
|
var req = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
common.error('response');
|
common.error('response');
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
common.error('response end');
|
common.error('response end');
|
||||||
server.close();
|
server.close();
|
||||||
responseComplete = true;
|
responseComplete = true;
|
||||||
@ -56,6 +56,6 @@ server.on('listening', function() {
|
|||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(responseComplete);
|
assert.ok(responseComplete);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,7 +28,7 @@ var http = require('http');
|
|||||||
// responds to a HEAD request, it does not send any body.
|
// responds to a HEAD request, it does not send any body.
|
||||||
// In this case it was sending '0\r\n\r\n'
|
// 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.writeHead(200); // broken: defaults to TE chunked
|
||||||
res.end();
|
res.end();
|
||||||
});
|
});
|
||||||
@ -36,14 +36,14 @@ server.listen(common.PORT);
|
|||||||
|
|
||||||
var responseComplete = false;
|
var responseComplete = false;
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
var req = http.request({
|
var req = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'HEAD',
|
method: 'HEAD',
|
||||||
path: '/'
|
path: '/'
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
common.error('response');
|
common.error('response');
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
common.error('response end');
|
common.error('response end');
|
||||||
server.close();
|
server.close();
|
||||||
responseComplete = true;
|
responseComplete = true;
|
||||||
@ -53,6 +53,6 @@ server.on('listening', function() {
|
|||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(responseComplete);
|
assert.ok(responseComplete);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -37,7 +37,7 @@ function reqHandler(req, res) {
|
|||||||
req.headers.host);
|
req.headers.host);
|
||||||
}
|
}
|
||||||
res.writeHead(200, {});
|
res.writeHead(200, {});
|
||||||
//process.nextTick(function() { res.end('ok'); });
|
//process.nextTick(function () { res.end('ok'); });
|
||||||
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);
|
console.error('listening on ' + common.PORT);
|
||||||
|
|
||||||
if (er) throw er;
|
if (er) throw er;
|
||||||
|
|||||||
@ -28,18 +28,18 @@ var responses = 0;
|
|||||||
var requests = 0;
|
var requests = 0;
|
||||||
var connection;
|
var connection;
|
||||||
|
|
||||||
var server = http.Server(function(req, res) {
|
var server = http.Server(function (req, res) {
|
||||||
requests++;
|
requests++;
|
||||||
assert.equal(req.connection, connection);
|
assert.equal(req.connection, connection);
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.end('hello world\n');
|
res.end('hello world\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
server.once('connection', function(c) {
|
server.once('connection', function (c) {
|
||||||
connection = c;
|
connection = c;
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
var callee = arguments.callee;
|
var callee = arguments.callee;
|
||||||
var request = http.get({
|
var request = http.get({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
@ -47,22 +47,22 @@ server.listen(common.PORT, function() {
|
|||||||
headers: {
|
headers: {
|
||||||
'Connection': 'Keep-alive'
|
'Connection': 'Keep-alive'
|
||||||
}
|
}
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
if (++responses < expected) {
|
if (++responses < expected) {
|
||||||
callee();
|
callee();
|
||||||
} else {
|
} else {
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}).on('error', function(e) {
|
}).on('error', function (e) {
|
||||||
console.log(e.message);
|
console.log(e.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
request.agent.maxSockets = 1;
|
request.agent.maxSockets = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(expected, responses);
|
assert.equal(expected, responses);
|
||||||
assert.equal(expected, requests);
|
assert.equal(expected, requests);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -27,7 +27,7 @@ var net = require('net');
|
|||||||
|
|
||||||
var gotResponse = false;
|
var gotResponse = false;
|
||||||
|
|
||||||
var server = net.createServer(function(conn) {
|
var server = net.createServer(function (conn) {
|
||||||
var body = 'Yet another node.js server.';
|
var body = 'Yet another node.js server.';
|
||||||
|
|
||||||
var response =
|
var response =
|
||||||
@ -40,20 +40,20 @@ var server = net.createServer(function(conn) {
|
|||||||
'\r\n' +
|
'\r\n' +
|
||||||
body;
|
body;
|
||||||
|
|
||||||
conn.write(response, function() {
|
conn.write(response, function () {
|
||||||
conn.destroy();
|
conn.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(common.PORT, function() {
|
server.listen(common.PORT, function () {
|
||||||
http.get({host: '127.0.0.1', port: common.PROXY_PORT}, function(res) {
|
http.get({host: '127.0.0.1', port: common.PROXY_PORT}, function (res) {
|
||||||
assert.equal(res.headers['content-type'],
|
assert.equal(res.headers['content-type'],
|
||||||
'text/plain;x-unix-mode=0600;name="hello.txt"');
|
'text/plain;x-unix-mode=0600;name="hello.txt"');
|
||||||
gotResponse = true;
|
gotResponse = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(gotResponse);
|
assert.ok(gotResponse);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,19 +36,19 @@ var headers = {'content-type': 'text/plain',
|
|||||||
'set-cookie': cookies,
|
'set-cookie': cookies,
|
||||||
'hello': 'world' };
|
'hello': 'world' };
|
||||||
|
|
||||||
var backend = http.createServer(function(req, res) {
|
var backend = http.createServer(function (req, res) {
|
||||||
common.debug('backend request');
|
common.debug('backend request');
|
||||||
res.writeHead(200, headers);
|
res.writeHead(200, headers);
|
||||||
res.write('hello world\n');
|
res.write('hello world\n');
|
||||||
res.end();
|
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));
|
common.debug('proxy req headers: ' + JSON.stringify(req.headers));
|
||||||
var proxy_req = http.get({
|
var proxy_req = http.get({
|
||||||
port: BACKEND_PORT,
|
port: BACKEND_PORT,
|
||||||
path: url.parse(req.url).pathname
|
path: url.parse(req.url).pathname
|
||||||
}, function(proxy_res) {
|
}, function (proxy_res) {
|
||||||
|
|
||||||
common.debug('proxy res headers: ' + JSON.stringify(proxy_res.headers));
|
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);
|
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
||||||
|
|
||||||
proxy_res.on('data', function(chunk) {
|
proxy_res.on('data', function (chunk) {
|
||||||
res.write(chunk);
|
res.write(chunk);
|
||||||
});
|
});
|
||||||
|
|
||||||
proxy_res.on('end', function() {
|
proxy_res.on('end', function () {
|
||||||
res.end();
|
res.end();
|
||||||
common.debug('proxy res');
|
common.debug('proxy res');
|
||||||
});
|
});
|
||||||
@ -79,7 +79,7 @@ function startReq() {
|
|||||||
var client = http.get({
|
var client = http.get({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
path: '/test'
|
path: '/test'
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
common.debug('got res');
|
common.debug('got res');
|
||||||
assert.equal(200, res.statusCode);
|
assert.equal(200, res.statusCode);
|
||||||
|
|
||||||
@ -88,8 +88,8 @@ function startReq() {
|
|||||||
assert.deepEqual(cookies, res.headers['set-cookie']);
|
assert.deepEqual(cookies, res.headers['set-cookie']);
|
||||||
|
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) { body += chunk; });
|
res.on('data', function (chunk) { body += chunk; });
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
proxy.close();
|
proxy.close();
|
||||||
backend.close();
|
backend.close();
|
||||||
common.debug('closed both');
|
common.debug('closed both');
|
||||||
@ -104,6 +104,6 @@ proxy.listen(PROXY_PORT, startReq);
|
|||||||
common.debug('listen backend');
|
common.debug('listen backend');
|
||||||
backend.listen(BACKEND_PORT, startReq);
|
backend.listen(BACKEND_PORT, startReq);
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(body, 'hello world\n');
|
assert.equal(body, 'hello world\n');
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,24 +25,24 @@ var http = require('http');
|
|||||||
|
|
||||||
var gotEnd = false;
|
var gotEnd = false;
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
res.writeHead(200);
|
res.writeHead(200);
|
||||||
res.write('a');
|
res.write('a');
|
||||||
|
|
||||||
req.on('close', function() {
|
req.on('close', function () {
|
||||||
console.error('aborted');
|
console.error('aborted');
|
||||||
gotEnd = true;
|
gotEnd = true;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(common.PORT);
|
server.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
console.error('make req');
|
console.error('make req');
|
||||||
http.get({
|
http.get({
|
||||||
port: common.PROXY_PORT
|
port: common.PROXY_PORT
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
console.error('got res');
|
console.error('got res');
|
||||||
res.on('data', function(data) {
|
res.on('data', function (data) {
|
||||||
console.error('destroy res');
|
console.error('destroy res');
|
||||||
res.destroy();
|
res.destroy();
|
||||||
server.close();
|
server.close();
|
||||||
@ -50,6 +50,6 @@ server.on('listening', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(gotEnd);
|
assert.ok(gotEnd);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -27,7 +27,7 @@ var common = require('../common');
|
|||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var http = require('http');
|
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.accept, 'abc, def, ghijklmnopqrst');
|
||||||
assert.equal(req.headers.host, 'foo');
|
assert.equal(req.headers.host, 'foo');
|
||||||
assert.equal(req.headers['x-foo'], 'bingo');
|
assert.equal(req.headers['x-foo'], 'bingo');
|
||||||
@ -39,7 +39,7 @@ var srv = http.createServer(function(req, res) {
|
|||||||
srv.close();
|
srv.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
srv.listen(common.PORT, function() {
|
srv.listen(common.PORT, function () {
|
||||||
http.get({
|
http.get({
|
||||||
host: 'localhost',
|
host: 'localhost',
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
|
|||||||
@ -25,7 +25,7 @@ var http = require('http');
|
|||||||
|
|
||||||
var nresponses = 0;
|
var nresponses = 0;
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
if (req.url == '/one') {
|
if (req.url == '/one') {
|
||||||
res.writeHead(200, [['set-cookie', 'A'],
|
res.writeHead(200, [['set-cookie', 'A'],
|
||||||
['content-type', 'text/plain']]);
|
['content-type', 'text/plain']]);
|
||||||
@ -39,21 +39,21 @@ var server = http.createServer(function(req, res) {
|
|||||||
});
|
});
|
||||||
server.listen(common.PORT);
|
server.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
//
|
//
|
||||||
// one set-cookie header
|
// 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.
|
// set-cookie headers are always return in an array.
|
||||||
// even if there is only one.
|
// even if there is only one.
|
||||||
assert.deepEqual(['A'], res.headers['set-cookie']);
|
assert.deepEqual(['A'], res.headers['set-cookie']);
|
||||||
assert.equal('text/plain', res.headers['content-type']);
|
assert.equal('text/plain', res.headers['content-type']);
|
||||||
|
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function (chunk) {
|
||||||
console.log(chunk.toString());
|
console.log(chunk.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
if (++nresponses == 2) {
|
if (++nresponses == 2) {
|
||||||
server.close();
|
server.close();
|
||||||
}
|
}
|
||||||
@ -62,15 +62,15 @@ server.on('listening', function() {
|
|||||||
|
|
||||||
// two set-cookie headers
|
// 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.deepEqual(['A', 'B'], res.headers['set-cookie']);
|
||||||
assert.equal('text/plain', res.headers['content-type']);
|
assert.equal('text/plain', res.headers['content-type']);
|
||||||
|
|
||||||
res.on('data', function(chunk) {
|
res.on('data', function (chunk) {
|
||||||
console.log(chunk.toString());
|
console.log(chunk.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', function() {
|
res.on('end', function () {
|
||||||
if (++nresponses == 2) {
|
if (++nresponses == 2) {
|
||||||
server.close();
|
server.close();
|
||||||
}
|
}
|
||||||
@ -79,6 +79,6 @@ server.on('listening', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(2, nresponses);
|
assert.equal(2, nresponses);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,7 +33,7 @@ var testsComplete = 0;
|
|||||||
var tests = [200, 202, 300, 404, 500];
|
var tests = [200, 202, 300, 404, 500];
|
||||||
var testIdx = 0;
|
var testIdx = 0;
|
||||||
|
|
||||||
var s = http.createServer(function(req, res) {
|
var s = http.createServer(function (req, res) {
|
||||||
var t = tests[testIdx];
|
var t = tests[testIdx];
|
||||||
res.writeHead(t, {'Content-Type': 'text/plain'});
|
res.writeHead(t, {'Content-Type': 'text/plain'});
|
||||||
console.log('--\nserver: statusCode after writeHead: ' + res.statusCode);
|
console.log('--\nserver: statusCode after writeHead: ' + res.statusCode);
|
||||||
@ -50,11 +50,11 @@ function nextTest() {
|
|||||||
}
|
}
|
||||||
var test = tests[testIdx];
|
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: expected status: ' + test);
|
||||||
console.log('client: statusCode: ' + response.statusCode);
|
console.log('client: statusCode: ' + response.statusCode);
|
||||||
assert.equal(response.statusCode, test);
|
assert.equal(response.statusCode, test);
|
||||||
response.on('end', function() {
|
response.on('end', function () {
|
||||||
testsComplete++;
|
testsComplete++;
|
||||||
testIdx += 1;
|
testIdx += 1;
|
||||||
nextTest();
|
nextTest();
|
||||||
@ -63,7 +63,7 @@ function nextTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.equal(4, testsComplete);
|
assert.equal(4, testsComplete);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -24,12 +24,12 @@ var assert = require('assert');
|
|||||||
var http = require('http');
|
var http = require('http');
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
common.error('got req');
|
common.error('got req');
|
||||||
throw new Error('This shouldn\'t happen.');
|
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');
|
common.error('got upgrade event');
|
||||||
// test that throwing an error from upgrade gets
|
// test that throwing an error from upgrade gets
|
||||||
// is uncaught
|
// is uncaught
|
||||||
@ -38,7 +38,7 @@ server.on('upgrade', function(req, socket, upgradeHead) {
|
|||||||
|
|
||||||
var gotError = false;
|
var gotError = false;
|
||||||
|
|
||||||
process.on('uncaughtException', function(e) {
|
process.on('uncaughtException', function (e) {
|
||||||
common.error('got \'clientError\' event');
|
common.error('got \'clientError\' event');
|
||||||
assert.equal('upgrade error', e.message);
|
assert.equal('upgrade error', e.message);
|
||||||
gotError = true;
|
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);
|
var c = net.createConnection(common.PROXY_PORT);
|
||||||
|
|
||||||
c.on('connect', function() {
|
c.on('connect', function () {
|
||||||
common.error('client wrote message');
|
common.error('client wrote message');
|
||||||
c.write('GET /blah HTTP/1.1\r\n' +
|
c.write('GET /blah HTTP/1.1\r\n' +
|
||||||
'Upgrade: WebSocket\r\n' +
|
'Upgrade: WebSocket\r\n' +
|
||||||
@ -57,16 +57,16 @@ server.listen(common.PORT, function() {
|
|||||||
'\r\n\r\nhello world');
|
'\r\n\r\nhello world');
|
||||||
});
|
});
|
||||||
|
|
||||||
c.on('end', function() {
|
c.on('end', function () {
|
||||||
c.end();
|
c.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
c.on('close', function() {
|
c.on('close', function () {
|
||||||
common.error('client close');
|
common.error('client close');
|
||||||
server.close();
|
server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
assert.ok(gotError);
|
assert.ok(gotError);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,7 +33,7 @@ var responses_recvd = 0;
|
|||||||
var body0 = '';
|
var body0 = '';
|
||||||
var body1 = '';
|
var body1 = '';
|
||||||
|
|
||||||
var server = http.Server(function(req, res) {
|
var server = http.Server(function (req, res) {
|
||||||
if (responses_sent == 0) {
|
if (responses_sent == 0) {
|
||||||
assert.equal('GET', req.method);
|
assert.equal('GET', req.method);
|
||||||
assert.equal('/hello', url.parse(req.url).pathname);
|
assert.equal('/hello', url.parse(req.url).pathname);
|
||||||
@ -52,7 +52,7 @@ var server = http.Server(function(req, res) {
|
|||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
req.on('end', function() {
|
req.on('end', function () {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
res.write('The path was ' + url.parse(req.url).pathname);
|
res.write('The path was ' + url.parse(req.url).pathname);
|
||||||
res.end();
|
res.end();
|
||||||
@ -63,39 +63,39 @@ var server = http.Server(function(req, res) {
|
|||||||
});
|
});
|
||||||
server.listen(common.PORT);
|
server.listen(common.PORT);
|
||||||
|
|
||||||
server.on('listening', function() {
|
server.on('listening', function () {
|
||||||
var agent = new http.Agent({ port: common.PROXY_PORT, maxSockets: 1 });
|
var agent = new http.Agent({ port: common.PROXY_PORT, maxSockets: 1 });
|
||||||
http.get({
|
http.get({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
path: '/hello',
|
path: '/hello',
|
||||||
headers: {'Accept': '*/*', 'Foo': 'bar'},
|
headers: {'Accept': '*/*', 'Foo': 'bar'},
|
||||||
agent: agent
|
agent: agent
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
assert.equal(200, res.statusCode);
|
assert.equal(200, res.statusCode);
|
||||||
responses_recvd += 1;
|
responses_recvd += 1;
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) { body0 += chunk; });
|
res.on('data', function (chunk) { body0 += chunk; });
|
||||||
common.debug('Got /hello response');
|
common.debug('Got /hello response');
|
||||||
});
|
});
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
var req = http.request({
|
var req = http.request({
|
||||||
port: common.PROXY_PORT,
|
port: common.PROXY_PORT,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: '/world',
|
path: '/world',
|
||||||
agent: agent
|
agent: agent
|
||||||
}, function(res) {
|
}, function (res) {
|
||||||
assert.equal(200, res.statusCode);
|
assert.equal(200, res.statusCode);
|
||||||
responses_recvd += 1;
|
responses_recvd += 1;
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
res.on('data', function(chunk) { body1 += chunk; });
|
res.on('data', function (chunk) { body1 += chunk; });
|
||||||
common.debug('Got /world response');
|
common.debug('Got /world response');
|
||||||
});
|
});
|
||||||
req.end();
|
req.end();
|
||||||
}, 1);
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', function () {
|
||||||
common.debug('responses_recvd: ' + responses_recvd);
|
common.debug('responses_recvd: ' + responses_recvd);
|
||||||
assert.equal(2, responses_recvd);
|
assert.equal(2, responses_recvd);
|
||||||
|
|
||||||
|
|||||||
@ -61,8 +61,8 @@ exports.createServer = function (options, callback) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.outputHeaders){
|
if (options.outputHeaders) {
|
||||||
Object.keys(options.outputHeaders).forEach(function(header){
|
Object.keys(options.outputHeaders).forEach(function (header) {
|
||||||
res.setHeader(header, options.outputHeaders[header]);
|
res.setHeader(header, options.outputHeaders[header]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -120,8 +120,8 @@ exports.createProxyServer = function (options, callback) {
|
|||||||
function requestHandler(req, res) {
|
function requestHandler(req, res) {
|
||||||
var buffer = httpProxy.buffer(req);
|
var buffer = httpProxy.buffer(req);
|
||||||
|
|
||||||
if (options.outputHeaders){
|
if (options.outputHeaders) {
|
||||||
Object.keys(options.outputHeaders).forEach(function(header){
|
Object.keys(options.outputHeaders).forEach(function (header) {
|
||||||
res.setHeader(header, options.outputHeaders[header]);
|
res.setHeader(header, options.outputHeaders[header]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user