Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何根据超时设置在终端中显示http.agent打开和关闭套接字_Node.js - Fatal编程技术网

Node.js 如何根据超时设置在终端中显示http.agent打开和关闭套接字

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

使用Node.js中的代理服务器将请求发送到httpbin.org。查找http.Agent的文档以及它如何处理连接池,并希望使用loadtest模拟并发请求,并在终端中显示基于代理配置的套接字打开和关闭;maxSockets、maxFreeSockets保持有效、超时等

我尝试在每次收到请求时打印代理,但希望以更清晰的方式查看它,而不是获取代理配置的大量文本

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