host: hostname,
port: port,
protocol,
proxyAuth: auth,
headers
}
});
options.agent = tunnelingAgent;
http.get(options, function(res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
работает:
{"p":"195.181.168.102","ip_decimal":3283462246,"country":"United States","country_eu":true,"country_iso":"US","city":"New York","hostname":"unn-195-181-168-102.datapacket.com","latitude":40.7157,"longitude":-74,"asn":"AS60068","asn_org":"Datacamp Limited"}
const proxyReq = (/https/i.test(protocol) ? https : http).get(
options,
res => {
res.headers = res.rawHeaders;
const statusCode = res.statusCode;
const resHeader = res.headers;
let resDataChunks = []; // array of data chunks or stream
const rawResChunks = []; // the original response chunks
let resDataStream = null;
let resSize = 0;
const finishCollecting = () => {
new Promise((fulfill, rejectParsing) => {
if (resDataStream) {
fulfill(resDataStream);
}
})
.then(serverResData => {
resolve({
statusCode,
header: resHeader,
body: serverResData,
rawBody: rawResChunks,
_res: res
});
})
.catch(e => {
reject(e);
});
};
res.on("data", chunk => {
rawResChunks.push(chunk);
if (resDataStream) {
resDataStream.push(chunk);
} else {
resSize += chunk.length;
resDataChunks.push(chunk);
if (resSize >= config.chunkSizeThreshold) {
resDataStream = new CommonReadableStream();
while (resDataChunks.length) {
resDataStream.push(resDataChunks.shift());
}
resDataChunks = null;
finishCollecting();
}
}
});
res.on("end", () => {
if (resDataStream) {
resDataStream.push(null);
} else {
finishCollecting();
}
});
}
);
proxyReq.on("error", reject);
proxyReq.end(reqData);
});
не работает
Error: Client network socket disconnected before secure TLS connection was established
чтож за пездетс
давай код на гист лучше
Обсуждают сегодня