@wiajs/req 1.7.10 → 1.7.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/req.js +119 -73
- package/dist/req.min.js +1 -1
- package/dist/web/req.cjs +524 -543
- package/package.json +1 -1
package/dist/req.js
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
(function (global, factory) {
|
|
7
7
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('node:url'), require('node:http'), require('node:https'), require('node:assert'), require('node:stream'), require('node:zlib'), require('path'), require('node:dns'), require('node:net'), require('node:tls'), require('events'), require('net'), require('buffer'), require('stream'), require('node:util'), require('node:events')) :
|
|
8
8
|
typeof define === 'function' && define.amd ? define(['node:url', 'node:http', 'node:https', 'node:assert', 'node:stream', 'node:zlib', 'path', 'node:dns', 'node:net', 'node:tls', 'events', 'net', 'buffer', 'stream', 'node:util', 'node:events'], factory) :
|
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.req = factory(global.url, global.http, global.https, global.assert$1, global.stream$1, global.zlib, global.require$$1, global.dns, global.net$1, global.tls, global.require$$0$
|
|
10
|
-
})(this, (function (url, http, https, assert$1, stream$1, zlib, require$$1, dns, net$1, tls, require$$0$
|
|
9
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.req = factory(global.url, global.http, global.https, global.assert$1, global.stream$1, global.zlib, global.require$$1, global.dns, global.net$1, global.tls, global.require$$0$2, global.require$$4, global.require$$0$1, global.require$$2, global.util$1, global.node_events));
|
|
10
|
+
})(this, (function (url, http, https, assert$1, stream$1, zlib, require$$1, dns, net$1, tls, require$$0$2, require$$4, require$$0$1, require$$2, util$1, node_events) { 'use strict';
|
|
11
11
|
|
|
12
12
|
function _interopNamespaceDefault(e) {
|
|
13
13
|
var n = Object.create(null);
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
var dns__namespace = /*#__PURE__*/_interopNamespaceDefault(dns);
|
|
30
|
-
var
|
|
30
|
+
var net__namespace = /*#__PURE__*/_interopNamespaceDefault(net$1);
|
|
31
31
|
var tls__namespace = /*#__PURE__*/_interopNamespaceDefault(tls);
|
|
32
32
|
|
|
33
33
|
function bind(fn, thisArg) {
|
|
@@ -757,6 +757,8 @@
|
|
|
757
757
|
return axiosError;
|
|
758
758
|
};
|
|
759
759
|
|
|
760
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
761
|
+
|
|
760
762
|
function getDefaultExportFromCjs (x) {
|
|
761
763
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
762
764
|
}
|
|
@@ -14000,15 +14002,18 @@
|
|
|
14000
14002
|
request.del = fn('delete');
|
|
14001
14003
|
request['delete'] = fn('delete');
|
|
14002
14004
|
|
|
14003
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
14004
14005
|
var build = {};
|
|
14006
|
+
|
|
14005
14007
|
var socksclient = {};
|
|
14008
|
+
|
|
14006
14009
|
var smartbuffer = {};
|
|
14010
|
+
|
|
14007
14011
|
var utils = {};
|
|
14012
|
+
|
|
14008
14013
|
Object.defineProperty(utils, "__esModule", {
|
|
14009
14014
|
value: true
|
|
14010
14015
|
});
|
|
14011
|
-
const buffer_1 = require$$0$
|
|
14016
|
+
const buffer_1 = require$$0$1;
|
|
14012
14017
|
/**
|
|
14013
14018
|
* Error strings
|
|
14014
14019
|
*/ const ERRORS$1 = {
|
|
@@ -14103,6 +14108,7 @@
|
|
|
14103
14108
|
}
|
|
14104
14109
|
}
|
|
14105
14110
|
utils.bigIntAndBufferInt64Check = bigIntAndBufferInt64Check;
|
|
14111
|
+
|
|
14106
14112
|
Object.defineProperty(smartbuffer, "__esModule", {
|
|
14107
14113
|
value: true
|
|
14108
14114
|
});
|
|
@@ -15228,7 +15234,9 @@
|
|
|
15228
15234
|
}
|
|
15229
15235
|
};
|
|
15230
15236
|
smartbuffer.SmartBuffer = SmartBuffer;
|
|
15237
|
+
|
|
15231
15238
|
var constants$3 = {};
|
|
15239
|
+
|
|
15232
15240
|
Object.defineProperty(constants$3, "__esModule", {
|
|
15233
15241
|
value: true
|
|
15234
15242
|
});
|
|
@@ -15337,8 +15345,11 @@
|
|
|
15337
15345
|
SocksClientState[SocksClientState["Disconnected"] = 11] = "Disconnected";
|
|
15338
15346
|
SocksClientState[SocksClientState["Error"] = 99] = "Error";
|
|
15339
15347
|
})(SocksClientState || (constants$3.SocksClientState = SocksClientState = {}));
|
|
15348
|
+
|
|
15340
15349
|
var helpers$2 = {};
|
|
15350
|
+
|
|
15341
15351
|
var util = {};
|
|
15352
|
+
|
|
15342
15353
|
Object.defineProperty(util, "__esModule", {
|
|
15343
15354
|
value: true
|
|
15344
15355
|
});
|
|
@@ -15365,9 +15376,13 @@
|
|
|
15365
15376
|
}
|
|
15366
15377
|
}
|
|
15367
15378
|
util.shuffleArray = shuffleArray;
|
|
15379
|
+
|
|
15368
15380
|
var ipAddress = {};
|
|
15381
|
+
|
|
15369
15382
|
var ipv4 = {};
|
|
15383
|
+
|
|
15370
15384
|
var common$2 = {};
|
|
15385
|
+
|
|
15371
15386
|
Object.defineProperty(common$2, "__esModule", {
|
|
15372
15387
|
value: true
|
|
15373
15388
|
});
|
|
@@ -15394,7 +15409,9 @@
|
|
|
15394
15409
|
};
|
|
15395
15410
|
}
|
|
15396
15411
|
common$2.isCorrect = isCorrect;
|
|
15412
|
+
|
|
15397
15413
|
var constants$2 = {};
|
|
15414
|
+
|
|
15398
15415
|
Object.defineProperty(constants$2, "__esModule", {
|
|
15399
15416
|
value: true
|
|
15400
15417
|
});
|
|
@@ -15403,7 +15420,9 @@
|
|
|
15403
15420
|
constants$2.GROUPS = 4;
|
|
15404
15421
|
constants$2.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
|
|
15405
15422
|
constants$2.RE_SUBNET_STRING = /\/\d{1,2}$/;
|
|
15423
|
+
|
|
15406
15424
|
var addressError = {};
|
|
15425
|
+
|
|
15407
15426
|
Object.defineProperty(addressError, "__esModule", {
|
|
15408
15427
|
value: true
|
|
15409
15428
|
});
|
|
@@ -15418,9 +15437,9 @@
|
|
|
15418
15437
|
}
|
|
15419
15438
|
};
|
|
15420
15439
|
addressError.AddressError = AddressError;
|
|
15421
|
-
|
|
15422
|
-
|
|
15423
|
-
|
|
15440
|
+
|
|
15441
|
+
var jsbn = {exports: {}};
|
|
15442
|
+
|
|
15424
15443
|
(function(module, exports) {
|
|
15425
15444
|
(function() {
|
|
15426
15445
|
// Copyright (c) 2005 Tom Wu
|
|
@@ -17001,8 +17020,10 @@
|
|
|
17001
17020
|
}).call(commonjsGlobal);
|
|
17002
17021
|
})(jsbn);
|
|
17003
17022
|
var jsbnExports = jsbn.exports;
|
|
17023
|
+
|
|
17004
17024
|
var sprintf = {};
|
|
17005
|
-
|
|
17025
|
+
|
|
17026
|
+
(function(exports) {
|
|
17006
17027
|
!function() {
|
|
17007
17028
|
var re = {
|
|
17008
17029
|
not_string: /[^s]/,
|
|
@@ -17036,7 +17057,8 @@
|
|
|
17036
17057
|
if (typeof parse_tree[i] === 'string') {
|
|
17037
17058
|
output += parse_tree[i];
|
|
17038
17059
|
} else if (typeof parse_tree[i] === 'object') {
|
|
17039
|
-
ph = parse_tree[i]
|
|
17060
|
+
ph = parse_tree[i] // convenience purposes only
|
|
17061
|
+
;
|
|
17040
17062
|
if (ph.keys) {
|
|
17041
17063
|
arg = argv[cursor];
|
|
17042
17064
|
for(k = 0; k < ph.keys.length; k++){
|
|
@@ -17195,6 +17217,7 @@
|
|
|
17195
17217
|
}
|
|
17196
17218
|
/* eslint-enable quote-props */ }(); // eslint-disable-line
|
|
17197
17219
|
})(sprintf);
|
|
17220
|
+
|
|
17198
17221
|
/* eslint-disable no-param-reassign */ var __createBinding$2 = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
17199
17222
|
if (k2 === undefined) k2 = k;
|
|
17200
17223
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -17504,8 +17527,11 @@
|
|
|
17504
17527
|
}
|
|
17505
17528
|
};
|
|
17506
17529
|
ipv4.Address4 = Address4;
|
|
17530
|
+
|
|
17507
17531
|
var ipv6 = {};
|
|
17532
|
+
|
|
17508
17533
|
var constants = {};
|
|
17534
|
+
|
|
17509
17535
|
Object.defineProperty(constants, "__esModule", {
|
|
17510
17536
|
value: true
|
|
17511
17537
|
});
|
|
@@ -17576,7 +17602,9 @@
|
|
|
17576
17602
|
*/ constants.RE_ZONE_STRING = /%.*$/;
|
|
17577
17603
|
constants.RE_URL = new RegExp(/^\[{0,1}([0-9a-f:]+)\]{0,1}/);
|
|
17578
17604
|
constants.RE_URL_WITH_PORT = new RegExp(/\[([0-9a-f:]+)\]:([0-9]{1,5})/);
|
|
17605
|
+
|
|
17579
17606
|
var helpers$1 = {};
|
|
17607
|
+
|
|
17580
17608
|
Object.defineProperty(helpers$1, "__esModule", {
|
|
17581
17609
|
value: true
|
|
17582
17610
|
});
|
|
@@ -17619,7 +17647,9 @@
|
|
|
17619
17647
|
});
|
|
17620
17648
|
}
|
|
17621
17649
|
helpers$1.simpleGroup = simpleGroup;
|
|
17650
|
+
|
|
17622
17651
|
var regularExpressions = {};
|
|
17652
|
+
|
|
17623
17653
|
var __createBinding$1 = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
17624
17654
|
if (k2 === undefined) k2 = k;
|
|
17625
17655
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -17727,6 +17757,7 @@
|
|
|
17727
17757
|
return groupPossibilities(possibilities);
|
|
17728
17758
|
}
|
|
17729
17759
|
regularExpressions.possibleElisions = possibleElisions;
|
|
17760
|
+
|
|
17730
17761
|
/* eslint-disable prefer-destructuring */ /* eslint-disable no-param-reassign */ var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
17731
17762
|
if (k2 === undefined) k2 = k;
|
|
17732
17763
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -18668,6 +18699,7 @@
|
|
|
18668
18699
|
}
|
|
18669
18700
|
};
|
|
18670
18701
|
ipv6.Address6 = Address6;
|
|
18702
|
+
|
|
18671
18703
|
(function(exports) {
|
|
18672
18704
|
var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
18673
18705
|
if (k2 === undefined) k2 = k;
|
|
@@ -18731,7 +18763,9 @@
|
|
|
18731
18763
|
exports.v6 = {
|
|
18732
18764
|
helpers
|
|
18733
18765
|
};
|
|
18766
|
+
|
|
18734
18767
|
})(ipAddress);
|
|
18768
|
+
|
|
18735
18769
|
Object.defineProperty(helpers$2, "__esModule", {
|
|
18736
18770
|
value: true
|
|
18737
18771
|
});
|
|
@@ -18881,7 +18915,9 @@
|
|
|
18881
18915
|
}
|
|
18882
18916
|
}
|
|
18883
18917
|
helpers$2.ipToBuffer = ipToBuffer;
|
|
18918
|
+
|
|
18884
18919
|
var receivebuffer = {};
|
|
18920
|
+
|
|
18885
18921
|
Object.defineProperty(receivebuffer, "__esModule", {
|
|
18886
18922
|
value: true
|
|
18887
18923
|
});
|
|
@@ -18925,6 +18961,7 @@
|
|
|
18925
18961
|
}
|
|
18926
18962
|
};
|
|
18927
18963
|
receivebuffer.ReceiveBuffer = ReceiveBuffer;
|
|
18964
|
+
|
|
18928
18965
|
(function(exports) {
|
|
18929
18966
|
var __awaiter = commonjsGlobal && commonjsGlobal.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
18930
18967
|
function adopt(value) {
|
|
@@ -18957,7 +18994,7 @@
|
|
|
18957
18994
|
value: true
|
|
18958
18995
|
});
|
|
18959
18996
|
exports.SocksClientError = exports.SocksClient = void 0;
|
|
18960
|
-
const events_1 = require$$0$
|
|
18997
|
+
const events_1 = require$$0$2;
|
|
18961
18998
|
const net = require$$4;
|
|
18962
18999
|
const smart_buffer_1 = smartbuffer;
|
|
18963
19000
|
const constants_1 = constants$3;
|
|
@@ -19687,7 +19724,9 @@
|
|
|
19687
19724
|
}
|
|
19688
19725
|
};
|
|
19689
19726
|
exports.SocksClient = SocksClient;
|
|
19727
|
+
|
|
19690
19728
|
})(socksclient);
|
|
19729
|
+
|
|
19691
19730
|
(function(exports) {
|
|
19692
19731
|
var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
19693
19732
|
if (k2 === undefined) k2 = k;
|
|
@@ -19712,8 +19751,10 @@
|
|
|
19712
19751
|
value: true
|
|
19713
19752
|
});
|
|
19714
19753
|
__exportStar(socksclient, exports);
|
|
19754
|
+
|
|
19715
19755
|
})(build);
|
|
19716
|
-
|
|
19756
|
+
|
|
19757
|
+
const log$3 = log$6({
|
|
19717
19758
|
env: `wia:agent:${name()}`
|
|
19718
19759
|
});
|
|
19719
19760
|
/** @typedef {import('stream').Duplex} Duplex */ /** @typedef {{protocol?: string, keepAlive: boolean} & import('net').TcpNetConnectOpts} HttpConnectOpts */ /** @typedef {{servername?:string, protocol?: string, port: number, keepAlive: boolean} & import('tls').ConnectionOptions} HttpsConnectOpts */ /** @typedef {HttpConnectOpts | HttpsConnectOpts} AgentConnectOpts */ /** @typedef {{protocol: string, host: string, port: number, type?: number, username?: string, userId?: string, password?: string}} Proxy */ /**
|
|
@@ -19756,7 +19797,7 @@
|
|
|
19756
19797
|
}
|
|
19757
19798
|
// Necessary for the TLS check with the proxy to succeed.
|
|
19758
19799
|
if (proxy.protocol === 'https:') connOpts.servername = proxy.host;
|
|
19759
|
-
log$
|
|
19800
|
+
log$3({
|
|
19760
19801
|
connOpts
|
|
19761
19802
|
}, 'connect request');
|
|
19762
19803
|
R = await new Promise((resolve, reject)=>{
|
|
@@ -19766,7 +19807,7 @@
|
|
|
19766
19807
|
request.removeAllListeners();
|
|
19767
19808
|
socket.removeAllListeners();
|
|
19768
19809
|
if (response.statusCode === 200) {
|
|
19769
|
-
log$
|
|
19810
|
+
log$3('Tunnel proxy connect Success.');
|
|
19770
19811
|
resolve({
|
|
19771
19812
|
socket,
|
|
19772
19813
|
err: null
|
|
@@ -19780,11 +19821,11 @@
|
|
|
19780
19821
|
err: new Error(`Bad response: ${response.statusCode}`)
|
|
19781
19822
|
});
|
|
19782
19823
|
// callback(new Error(`Bad response: ${response.statusCode}`), null)
|
|
19783
|
-
log$
|
|
19824
|
+
log$3.error('Tunnel proxy connect Fail.');
|
|
19784
19825
|
}
|
|
19785
19826
|
});
|
|
19786
19827
|
request.once('timeout', ()=>{
|
|
19787
|
-
log$
|
|
19828
|
+
log$3.error('connect timeout');
|
|
19788
19829
|
request.destroy(new Error('Proxy timeout'));
|
|
19789
19830
|
});
|
|
19790
19831
|
request.once('error', (err)=>{
|
|
@@ -19793,13 +19834,13 @@
|
|
|
19793
19834
|
socket: null,
|
|
19794
19835
|
err
|
|
19795
19836
|
});
|
|
19796
|
-
log$
|
|
19837
|
+
log$3.err(err, 'connect');
|
|
19797
19838
|
// callback(err, null)
|
|
19798
19839
|
});
|
|
19799
19840
|
request.end();
|
|
19800
19841
|
});
|
|
19801
19842
|
} catch (e) {
|
|
19802
|
-
log$
|
|
19843
|
+
log$3.err(e, 'connect');
|
|
19803
19844
|
R.err = e;
|
|
19804
19845
|
}
|
|
19805
19846
|
return R;
|
|
@@ -19840,20 +19881,20 @@
|
|
|
19840
19881
|
command: 'connect',
|
|
19841
19882
|
timeout: timeout ?? undefined
|
|
19842
19883
|
};
|
|
19843
|
-
log$
|
|
19884
|
+
log$3({
|
|
19844
19885
|
connOpt
|
|
19845
19886
|
}, 'connect');
|
|
19846
19887
|
const { socket } = await build.SocksClient.createConnection(connOpt);
|
|
19847
19888
|
if (socket) {
|
|
19848
19889
|
R = socket;
|
|
19849
|
-
log$
|
|
19890
|
+
log$3('Socks proxy connect Success.');
|
|
19850
19891
|
if (timeout) {
|
|
19851
19892
|
socket.setTimeout(timeout);
|
|
19852
19893
|
socket.on('timeout', ()=>socket.destroy());
|
|
19853
19894
|
}
|
|
19854
|
-
} else log$
|
|
19895
|
+
} else log$3.error('Socks proxy connect Fail.');
|
|
19855
19896
|
} catch (e) {
|
|
19856
|
-
log$
|
|
19897
|
+
log$3.err(e, 'socksConnect');
|
|
19857
19898
|
}
|
|
19858
19899
|
return R;
|
|
19859
19900
|
}
|
|
@@ -19917,7 +19958,7 @@
|
|
|
19917
19958
|
};
|
|
19918
19959
|
// log({proxy}, 'parseURL')
|
|
19919
19960
|
} catch (e) {
|
|
19920
|
-
log$
|
|
19961
|
+
log$3.err(e, 'parseURL');
|
|
19921
19962
|
}
|
|
19922
19963
|
return R;
|
|
19923
19964
|
}
|
|
@@ -19933,14 +19974,15 @@
|
|
|
19933
19974
|
}
|
|
19934
19975
|
return R;
|
|
19935
19976
|
}
|
|
19936
|
-
|
|
19977
|
+
|
|
19978
|
+
const log$2 = log$6({
|
|
19937
19979
|
env: `wia:agent:${name()}`
|
|
19938
19980
|
});
|
|
19939
19981
|
/** @typedef {import('stream').Duplex} Duplex */ /** @typedef {import('./tunnel').AgentConnectOpts} AgentConnectOpts */ /** @typedef {import('./tunnel').Proxy} Proxy */ /** @typedef {http.AgentOptions & https.AgentOptions & {proxy: string|Proxy, proxyOpts?: *, tunnel?: boolean}} AgentOpts */ /**
|
|
19940
19982
|
* 隧道代理,实现HTTPS目的网址访问
|
|
19941
19983
|
* 重写 https.Agent的createConnection
|
|
19942
19984
|
* 使用 HTTP 1.1 CONNECT 协议,通过http或https连接代理服务器,建立TLS隧道,
|
|
19943
|
-
*/
|
|
19985
|
+
*/ class HttpsAgent extends https.Agent {
|
|
19944
19986
|
static{
|
|
19945
19987
|
this.protocols = [
|
|
19946
19988
|
'http',
|
|
@@ -19957,12 +19999,12 @@
|
|
|
19957
19999
|
*/ constructor(opts){
|
|
19958
20000
|
const { proxy, proxyOpts, ...opt } = opts;
|
|
19959
20001
|
super(opt);
|
|
19960
|
-
if (opt.timeout) this.timeout = opt.timeout
|
|
20002
|
+
if (opt.timeout) this.timeout = opt.timeout // super(opt) 无效
|
|
20003
|
+
;
|
|
19961
20004
|
this.opt = opt;
|
|
19962
20005
|
let lookup = false;
|
|
19963
20006
|
/** @type {Proxy} */ let px;
|
|
19964
|
-
if (typeof proxy === 'string') // let proxy = `
|
|
19965
|
-
// let proxy = `socks5h://${username}:${password}@${proxy_ip}:${proxy_port}`
|
|
20007
|
+
if (typeof proxy === 'string') // let proxy = `socks5h://${username}:${password}@${proxy_ip}:${proxy_port}`
|
|
19966
20008
|
({ proxy: px, lookup } = parseURL(new URL(proxy)));
|
|
19967
20009
|
else px = proxy;
|
|
19968
20010
|
this.lookup = lookup;
|
|
@@ -19977,8 +20019,8 @@
|
|
|
19977
20019
|
this.proxy = px;
|
|
19978
20020
|
this.proxyOpts = proxyOpts || {};
|
|
19979
20021
|
this.tunnel = true;
|
|
19980
|
-
log$
|
|
19981
|
-
} else log$
|
|
20022
|
+
log$2('Create HttpsAgent proxy :%o', this.proxy);
|
|
20023
|
+
} else log$2.error('Create HttpsAgent error, not found proxy!');
|
|
19982
20024
|
}
|
|
19983
20025
|
/**
|
|
19984
20026
|
* 默认情况下,此函数与 net.createConnection() 相同。
|
|
@@ -19996,16 +20038,16 @@
|
|
|
19996
20038
|
// @ts-ignore
|
|
19997
20039
|
const socket = super.createConnection(opts);
|
|
19998
20040
|
socket.once('connect', ()=>{
|
|
19999
|
-
log$
|
|
20041
|
+
log$2('Create Https Socket Success.');
|
|
20000
20042
|
cb(null, socket);
|
|
20001
20043
|
});
|
|
20002
|
-
socket.once('close', ()=>log$
|
|
20044
|
+
socket.once('close', ()=>log$2('Https Socket close.'));
|
|
20003
20045
|
} else {
|
|
20004
20046
|
if ([
|
|
20005
20047
|
'http:',
|
|
20006
20048
|
'https:'
|
|
20007
20049
|
].includes(proxy.protocol)) {
|
|
20008
|
-
Promise.resolve().then(()=>connect(opts, proxy, proxyOpts))// @ts-ignore
|
|
20050
|
+
Promise.resolve().then(()=>connect(opts, proxy, proxyOpts)) // @ts-ignore
|
|
20009
20051
|
.then(({ socket, err })=>{
|
|
20010
20052
|
if (socket && opts.protocol === 'https:') {
|
|
20011
20053
|
// @ts-ignore
|
|
@@ -20014,13 +20056,13 @@
|
|
|
20014
20056
|
socket
|
|
20015
20057
|
});
|
|
20016
20058
|
if (secureSocket) {
|
|
20017
|
-
secureSocket?.once('close', ()=>log$
|
|
20018
|
-
log$
|
|
20059
|
+
secureSocket?.once('close', ()=>log$2('Secure Socket close.'));
|
|
20060
|
+
log$2('Create Secure Socket Success.');
|
|
20019
20061
|
cb(null, secureSocket);
|
|
20020
|
-
} else log$
|
|
20062
|
+
} else log$2.error('Create Secure Socket Fail.');
|
|
20021
20063
|
} else if (err) cb(err, null);
|
|
20022
20064
|
}).catch((err)=>{
|
|
20023
|
-
log$
|
|
20065
|
+
log$2.err(err);
|
|
20024
20066
|
cb(err);
|
|
20025
20067
|
});
|
|
20026
20068
|
} else {
|
|
@@ -20032,19 +20074,20 @@
|
|
|
20032
20074
|
socket
|
|
20033
20075
|
});
|
|
20034
20076
|
if (secureSocket) {
|
|
20035
|
-
log$
|
|
20077
|
+
log$2('Created secureSocket Success.');
|
|
20036
20078
|
cb(null, secureSocket);
|
|
20037
|
-
} else log$
|
|
20079
|
+
} else log$2.error('Creat secureSocket Fail.');
|
|
20038
20080
|
}
|
|
20039
20081
|
}).catch((err)=>{
|
|
20040
|
-
log$
|
|
20082
|
+
log$2.err(err, 'createConnection');
|
|
20041
20083
|
cb(err);
|
|
20042
20084
|
});
|
|
20043
20085
|
}
|
|
20044
20086
|
}
|
|
20045
20087
|
}
|
|
20046
|
-
}
|
|
20047
|
-
|
|
20088
|
+
}
|
|
20089
|
+
|
|
20090
|
+
const log$1 = log$6({
|
|
20048
20091
|
env: `wia:agent:${name()}`
|
|
20049
20092
|
});
|
|
20050
20093
|
/** @typedef {import('stream').Duplex} Duplex */ /** @typedef {import('./tunnel').AgentConnectOpts & {hostname?: string, path?: string, pathname?: string, keepAlive: boolean}} AgentConnectOpts */ /** @typedef {import('./tunnel').Proxy} Proxy */ /** @typedef {http.AgentOptions & https.AgentOptions & {proxy: string|Proxy, proxyOpts?: *, tunnel?: boolean}} AgentOpts */ /**
|
|
@@ -20085,7 +20128,7 @@
|
|
|
20085
20128
|
maxFreeSockets: 5, // 同一目的主机空闲最大连接,超过关闭。keepAlive true 时有效。默认值:256
|
|
20086
20129
|
timeout: 10000, // 建立连接时长,缺省 30000
|
|
20087
20130
|
})
|
|
20088
|
-
*/
|
|
20131
|
+
*/ class HttpAgent extends http.Agent {
|
|
20089
20132
|
static{
|
|
20090
20133
|
this.protocols = [
|
|
20091
20134
|
'http',
|
|
@@ -20102,7 +20145,8 @@
|
|
|
20102
20145
|
*/ constructor(opts){
|
|
20103
20146
|
const { proxy, proxyOpts, tunnel, ...opt } = opts;
|
|
20104
20147
|
super(opt);
|
|
20105
|
-
if (opt.timeout) this.timeout = opt.timeout
|
|
20148
|
+
if (opt.timeout) this.timeout = opt.timeout // super(opt) 无效
|
|
20149
|
+
;
|
|
20106
20150
|
this.opt = opt;
|
|
20107
20151
|
let lookup = false;
|
|
20108
20152
|
/** @type {Proxy} */ let px;
|
|
@@ -20124,11 +20168,10 @@
|
|
|
20124
20168
|
if ([
|
|
20125
20169
|
'http:',
|
|
20126
20170
|
'https:'
|
|
20127
|
-
].includes(px.protocol))
|
|
20128
|
-
this.tunnel = tunnel ?? false;
|
|
20171
|
+
].includes(px.protocol)) this.tunnel = tunnel ?? false;
|
|
20129
20172
|
else this.tunnel = true;
|
|
20130
|
-
log$
|
|
20131
|
-
} else log$
|
|
20173
|
+
log$1('Create HttpAgent proxy: %o tunnel: %d', this.proxy, this.tunnel);
|
|
20174
|
+
} else log$1.error('Create HttpAgent error, not found proxy!');
|
|
20132
20175
|
}
|
|
20133
20176
|
/**
|
|
20134
20177
|
* 修改 request,host 改为代理,目的地写入 path
|
|
@@ -20141,16 +20184,17 @@
|
|
|
20141
20184
|
const { proxy } = _;
|
|
20142
20185
|
if (proxy) {
|
|
20143
20186
|
let headers = req.getHeaders();
|
|
20144
|
-
log$
|
|
20187
|
+
log$1({
|
|
20145
20188
|
headers: {
|
|
20146
20189
|
...headers
|
|
20147
20190
|
}
|
|
20148
|
-
}, 'addRequest')
|
|
20191
|
+
}, 'addRequest') // 消除 [Object: null prototype]
|
|
20192
|
+
;
|
|
20149
20193
|
// 非隧道,转发模式,修改req连接代理
|
|
20150
20194
|
if (!_.tunnel) {
|
|
20151
20195
|
_.setReqProps(req, opts);
|
|
20152
20196
|
headers = req.getHeaders();
|
|
20153
|
-
log$
|
|
20197
|
+
log$1({
|
|
20154
20198
|
headers: {
|
|
20155
20199
|
...headers
|
|
20156
20200
|
}
|
|
@@ -20171,7 +20215,8 @@
|
|
|
20171
20215
|
if (!proxy) return;
|
|
20172
20216
|
// log({opts}, 'setReqProps')
|
|
20173
20217
|
const protocol = opts.protocol;
|
|
20174
|
-
const host = req.getHeader('host') || 'localhost'
|
|
20218
|
+
const host = req.getHeader('host') || 'localhost' // 带端口
|
|
20219
|
+
;
|
|
20175
20220
|
const base = `${protocol}//${host}`;
|
|
20176
20221
|
const url = new URL(req.path, base);
|
|
20177
20222
|
if (opts.port !== 80) url.port = String(opts.port);
|
|
@@ -20183,7 +20228,7 @@
|
|
|
20183
20228
|
443
|
|
20184
20229
|
].includes(opts.port) ? `:${opts.port}` : '';
|
|
20185
20230
|
const path2 = `${opts.protocol}//${opts.hostname}${port}${opts.pathname ?? ''}`;
|
|
20186
|
-
log$
|
|
20231
|
+
log$1({
|
|
20187
20232
|
path: req.path,
|
|
20188
20233
|
path2
|
|
20189
20234
|
}, 'setReqProps');
|
|
@@ -20226,12 +20271,12 @@
|
|
|
20226
20271
|
const _ = this;
|
|
20227
20272
|
const { proxy, proxyOpts } = _;
|
|
20228
20273
|
if (!proxy) {
|
|
20229
|
-
/** @type {net.Socket} */ const socket =
|
|
20274
|
+
/** @type {net.Socket} */ const socket = net__namespace.createConnection(opts);
|
|
20230
20275
|
socket.once('connect', ()=>{
|
|
20231
|
-
log$
|
|
20276
|
+
log$1('Create Http Socket Success.');
|
|
20232
20277
|
cb(null, socket);
|
|
20233
20278
|
});
|
|
20234
|
-
socket.once('close', ()=>log$
|
|
20279
|
+
socket.once('close', ()=>log$1('Http Socket close.'));
|
|
20235
20280
|
} else {
|
|
20236
20281
|
// 非隧道,连接代理转发
|
|
20237
20282
|
if (!_.tunnel) {
|
|
@@ -20243,44 +20288,44 @@
|
|
|
20243
20288
|
// Create a socket connection to the proxy server.
|
|
20244
20289
|
/** @type {net.Socket} */ let socket;
|
|
20245
20290
|
if (proxy.protocol === 'https:') {
|
|
20246
|
-
log$
|
|
20291
|
+
log$1({
|
|
20247
20292
|
connOpts
|
|
20248
20293
|
}, 'Creating `tls.Socket`');
|
|
20249
20294
|
socket = tls__namespace.connect(connOpts);
|
|
20250
20295
|
} else {
|
|
20251
|
-
log$
|
|
20296
|
+
log$1({
|
|
20252
20297
|
connOpts
|
|
20253
20298
|
}, 'Creating `net.Socket`');
|
|
20254
20299
|
// socket = super.createConnection(connOpt)
|
|
20255
|
-
socket =
|
|
20300
|
+
socket = net__namespace.createConnection(connOpts);
|
|
20256
20301
|
}
|
|
20257
20302
|
socket.once('connect', ()=>{
|
|
20258
|
-
log$
|
|
20303
|
+
log$1('Create Xfer Socket Success.');
|
|
20259
20304
|
cb(null, socket);
|
|
20260
20305
|
});
|
|
20261
|
-
socket.once('close', ()=>log$
|
|
20306
|
+
socket.once('close', ()=>log$1('Xfer Socket close.'));
|
|
20262
20307
|
} else {
|
|
20263
20308
|
// HttpAgent隧道模式,只支持 http目标网址,https网址请使用 httpsAgent
|
|
20264
20309
|
if ([
|
|
20265
20310
|
'http:',
|
|
20266
20311
|
'https:'
|
|
20267
20312
|
].includes(proxy.protocol)) {
|
|
20268
|
-
Promise.resolve().then(()=>connect(opts, this.proxy, this.proxyOpts))// @ts-ignore
|
|
20313
|
+
Promise.resolve().then(()=>connect(opts, this.proxy, this.proxyOpts)) // @ts-ignore
|
|
20269
20314
|
.then(({ socket, err })=>{
|
|
20270
|
-
socket?.once('close', ()=>log$
|
|
20315
|
+
socket?.once('close', ()=>log$1('Tunnel Socket close.'));
|
|
20271
20316
|
if (socket && opts.protocol === 'http:') {
|
|
20272
|
-
log$
|
|
20317
|
+
log$1('Create Tunnel Socket Success.');
|
|
20273
20318
|
cb(null, socket);
|
|
20274
20319
|
} else if (socket) {
|
|
20275
20320
|
socket.destroy();
|
|
20276
|
-
log$
|
|
20321
|
+
log$1.error('Create Tunnel Socket Success, protocol not http.');
|
|
20277
20322
|
cb(new Error('Bad Protocol.'), null);
|
|
20278
20323
|
} else if (err) {
|
|
20279
|
-
log$
|
|
20324
|
+
log$1.error('Create Tunnel Socket Fail.');
|
|
20280
20325
|
cb(err, null);
|
|
20281
20326
|
}
|
|
20282
20327
|
}).catch((err)=>{
|
|
20283
|
-
log$
|
|
20328
|
+
log$1.err(err, 'createConnection');
|
|
20284
20329
|
cb(err, null);
|
|
20285
20330
|
});
|
|
20286
20331
|
} else {
|
|
@@ -20289,19 +20334,20 @@
|
|
|
20289
20334
|
};
|
|
20290
20335
|
Promise.resolve().then(()=>socksConnect(opts, px, this.lookup)).then((socket)=>{
|
|
20291
20336
|
if (socket) {
|
|
20292
|
-
log$
|
|
20337
|
+
log$1('Created Socket Success.');
|
|
20293
20338
|
cb(null, socket);
|
|
20294
|
-
} else log$
|
|
20339
|
+
} else log$1.error('Creat Socket Fail.');
|
|
20295
20340
|
}).catch((err)=>{
|
|
20296
|
-
log$
|
|
20341
|
+
log$1.err(err, 'createConnection');
|
|
20297
20342
|
cb(err);
|
|
20298
20343
|
});
|
|
20299
20344
|
}
|
|
20300
20345
|
}
|
|
20301
20346
|
}
|
|
20302
20347
|
}
|
|
20303
|
-
}
|
|
20304
|
-
|
|
20348
|
+
}
|
|
20349
|
+
|
|
20350
|
+
/** @typedef {import('./tunnel.js').Proxy} Proxy */ /** @typedef {http.AgentOptions & https.AgentOptions & {proxy: string|Proxy, proxyOpts?: *, tunnel?: boolean}} AgentOpts */ class Agent {
|
|
20305
20351
|
/**
|
|
20306
20352
|
* @param {AgentOpts} options
|
|
20307
20353
|
*/ constructor(options){
|
|
@@ -20316,7 +20362,7 @@
|
|
|
20316
20362
|
};
|
|
20317
20363
|
this.https = new HttpsAgent(httpsOpt);
|
|
20318
20364
|
}
|
|
20319
|
-
}
|
|
20365
|
+
}
|
|
20320
20366
|
|
|
20321
20367
|
/**
|
|
20322
20368
|
* Resolve or reject a Promise based on response status.
|