Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// оригинальный форк
const https = require('https')
const net = require('net')
const url = require('url')
Expand Down Expand Up @@ -32,6 +33,7 @@ class myAgent extends https.Agent {
options.keepAlive = true
}
super(options)
if (options.timeout) this._timeout = options.timeout
}

createConnectionHttpsAfterHttp (options, cb) {
Expand All @@ -48,6 +50,17 @@ class myAgent extends https.Agent {
proxySocket.once('error', errorListener)
proxySocket.once('end',endListener)

if (this._timeout) {
proxySocket.setTimeout(this._timeout);

proxySocket.on('timeout', () => {
//proxySocket.end();
const err/* : NodeJS.ErrnoException */ = new Error(`A "socket" was not created for HTTP request before ${this._timeout}ms`);
err.code = 'ETIMEOUT';
proxySocket.destroy(err)
});
}

let response = ''
const dataListener = (data) => {
response += data.toString()
Expand Down