Node.js 如何根据超时设置在终端中显示http.agent打开和关闭套接字
使用Node.js中的代理服务器将请求发送到httpbin.org。查找http.Agent的文档以及它如何处理连接池,并希望使用loadtest模拟并发请求,并在终端中显示基于代理配置的套接字打开和关闭;maxSockets、maxFreeSockets保持有效、超时等 我尝试在每次收到请求时打印代理,但希望以更清晰的方式查看它,而不是获取代理配置的大量文本Node.js 如何根据超时设置在终端中显示http.agent打开和关闭套接字,node.js,Node.js,使用Node.js中的代理服务器将请求发送到httpbin.org。查找http.Agent的文档以及它如何处理连接池,并希望使用loadtest模拟并发请求,并在终端中显示基于代理配置的套接字打开和关闭;maxSockets、maxFreeSockets保持有效、超时等 我尝试在每次收到请求时打印代理,但希望以更清晰的方式查看它,而不是获取代理配置的大量文本 var fs = require('fs'), https = require('https'), httpProxy
var fs = require('fs'),
https = require('https'),
httpProxy = require('http-proxy'),
http = require('http')
// Custom Agent
var proxyAgent = new http.Agent({ keepAlive: true, maxSockets: 3, keepAliveMsecs: 30000, timeout: 30000 });
// Create your proxy server
var proxy = httpProxy.createProxyServer({agent: proxyAgent});
// Create your target server
var server = http.createServer(function(req, res) {
proxy.web(req, res, { target: 'http://httpbin.org/' });
});
server.listen(8080);
console.log("running on 8080")
proxy.on('proxyRes', function (res) {
console.log('Opened socket: ' + res.socket.localPort);
//console.log(proxyAgent)
});