@theia/request 1.48.1 → 1.48.2
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/README.md +29 -29
- package/lib/common-request-service.d.ts +75 -75
- package/lib/common-request-service.js +84 -84
- package/lib/index.d.ts +16 -16
- package/lib/index.js +19 -19
- package/lib/node-request-service.d.ts +38 -38
- package/lib/node-request-service.js +134 -134
- package/lib/package.spec.d.ts +15 -15
- package/lib/package.spec.js +25 -25
- package/lib/proxy.d.ts +23 -23
- package/lib/proxy.js +50 -50
- package/package.json +2 -2
- package/src/common-request-service.ts +127 -127
- package/src/index.ts +17 -17
- package/src/node-request-service.ts +165 -165
- package/src/package.spec.ts +28 -28
- package/src/proxy.ts +61 -61
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (C) 2022 TypeFox and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
*
|
|
9
|
-
* This Source Code may also be made available under the following Secondary
|
|
10
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
* with the GNU Classpath Exception which is available at
|
|
13
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.NodeRequestService = void 0;
|
|
19
|
-
const http = require("http");
|
|
20
|
-
const https = require("https");
|
|
21
|
-
const proxy_1 = require("./proxy");
|
|
22
|
-
const zlib_1 = require("zlib");
|
|
23
|
-
;
|
|
24
|
-
class NodeRequestService {
|
|
25
|
-
getNodeRequest(options) {
|
|
26
|
-
const endpoint = new URL(options.url);
|
|
27
|
-
const module = endpoint.protocol === 'https:' ? https : http;
|
|
28
|
-
return module.request;
|
|
29
|
-
}
|
|
30
|
-
async getProxyUrl(url) {
|
|
31
|
-
return this.proxyUrl;
|
|
32
|
-
}
|
|
33
|
-
async configure(config) {
|
|
34
|
-
if (config.proxyUrl !== undefined) {
|
|
35
|
-
this.proxyUrl = config.proxyUrl;
|
|
36
|
-
}
|
|
37
|
-
if (config.strictSSL !== undefined) {
|
|
38
|
-
this.strictSSL = config.strictSSL;
|
|
39
|
-
}
|
|
40
|
-
if (config.proxyAuthorization !== undefined) {
|
|
41
|
-
this.authorization = config.proxyAuthorization;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
async processOptions(options) {
|
|
45
|
-
var _a;
|
|
46
|
-
const { strictSSL } = this;
|
|
47
|
-
options.strictSSL = (_a = options.strictSSL) !== null && _a !== void 0 ? _a : strictSSL;
|
|
48
|
-
const agent = options.agent ? options.agent : (0, proxy_1.getProxyAgent)(options.url || '', process.env, {
|
|
49
|
-
proxyUrl: await this.getProxyUrl(options.url),
|
|
50
|
-
strictSSL: options.strictSSL
|
|
51
|
-
});
|
|
52
|
-
options.agent = agent;
|
|
53
|
-
const authorization = options.proxyAuthorization || this.authorization;
|
|
54
|
-
if (authorization) {
|
|
55
|
-
options.headers = {
|
|
56
|
-
...(options.headers || {}),
|
|
57
|
-
'Proxy-Authorization': authorization
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
options.headers = {
|
|
61
|
-
'Accept-Encoding': 'gzip',
|
|
62
|
-
...(options.headers || {}),
|
|
63
|
-
};
|
|
64
|
-
return options;
|
|
65
|
-
}
|
|
66
|
-
request(options, token) {
|
|
67
|
-
return new Promise(async (resolve, reject) => {
|
|
68
|
-
options = await this.processOptions(options);
|
|
69
|
-
const endpoint = new URL(options.url);
|
|
70
|
-
const rawRequest = options.getRawRequest
|
|
71
|
-
? options.getRawRequest(options)
|
|
72
|
-
: this.getNodeRequest(options);
|
|
73
|
-
const opts = {
|
|
74
|
-
hostname: endpoint.hostname,
|
|
75
|
-
port: endpoint.port ? parseInt(endpoint.port) : (endpoint.protocol === 'https:' ? 443 : 80),
|
|
76
|
-
protocol: endpoint.protocol,
|
|
77
|
-
path: endpoint.pathname + endpoint.search,
|
|
78
|
-
method: options.type || 'GET',
|
|
79
|
-
headers: options.headers,
|
|
80
|
-
agent: options.agent,
|
|
81
|
-
rejectUnauthorized: !!options.strictSSL
|
|
82
|
-
};
|
|
83
|
-
if (options.user && options.password) {
|
|
84
|
-
opts.auth = options.user + ':' + options.password;
|
|
85
|
-
}
|
|
86
|
-
const req = rawRequest(opts, async (res) => {
|
|
87
|
-
var _a;
|
|
88
|
-
const followRedirects = (_a = options.followRedirects) !== null && _a !== void 0 ? _a : 3;
|
|
89
|
-
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers.location) {
|
|
90
|
-
this.request({
|
|
91
|
-
...options,
|
|
92
|
-
url: res.headers.location,
|
|
93
|
-
followRedirects: followRedirects - 1
|
|
94
|
-
}, token).then(resolve, reject);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
const chunks = [];
|
|
98
|
-
const stream = res.headers['content-encoding'] === 'gzip' ? res.pipe((0, zlib_1.createGunzip)()) : res;
|
|
99
|
-
stream.on('data', chunk => {
|
|
100
|
-
chunks.push(chunk);
|
|
101
|
-
});
|
|
102
|
-
stream.on('end', () => {
|
|
103
|
-
const buffer = Buffer.concat(chunks);
|
|
104
|
-
resolve({
|
|
105
|
-
url: options.url,
|
|
106
|
-
res: {
|
|
107
|
-
headers: res.headers,
|
|
108
|
-
statusCode: res.statusCode
|
|
109
|
-
},
|
|
110
|
-
buffer
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
stream.on('error', reject);
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
req.on('error', reject);
|
|
117
|
-
if (options.timeout) {
|
|
118
|
-
req.setTimeout(options.timeout);
|
|
119
|
-
}
|
|
120
|
-
if (options.data) {
|
|
121
|
-
req.write(options.data);
|
|
122
|
-
}
|
|
123
|
-
req.end();
|
|
124
|
-
token === null || token === void 0 ? void 0 : token.onCancellationRequested(() => {
|
|
125
|
-
req.abort();
|
|
126
|
-
reject();
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async resolveProxy(url) {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
exports.NodeRequestService = NodeRequestService;
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.NodeRequestService = void 0;
|
|
19
|
+
const http = require("http");
|
|
20
|
+
const https = require("https");
|
|
21
|
+
const proxy_1 = require("./proxy");
|
|
22
|
+
const zlib_1 = require("zlib");
|
|
23
|
+
;
|
|
24
|
+
class NodeRequestService {
|
|
25
|
+
getNodeRequest(options) {
|
|
26
|
+
const endpoint = new URL(options.url);
|
|
27
|
+
const module = endpoint.protocol === 'https:' ? https : http;
|
|
28
|
+
return module.request;
|
|
29
|
+
}
|
|
30
|
+
async getProxyUrl(url) {
|
|
31
|
+
return this.proxyUrl;
|
|
32
|
+
}
|
|
33
|
+
async configure(config) {
|
|
34
|
+
if (config.proxyUrl !== undefined) {
|
|
35
|
+
this.proxyUrl = config.proxyUrl;
|
|
36
|
+
}
|
|
37
|
+
if (config.strictSSL !== undefined) {
|
|
38
|
+
this.strictSSL = config.strictSSL;
|
|
39
|
+
}
|
|
40
|
+
if (config.proxyAuthorization !== undefined) {
|
|
41
|
+
this.authorization = config.proxyAuthorization;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async processOptions(options) {
|
|
45
|
+
var _a;
|
|
46
|
+
const { strictSSL } = this;
|
|
47
|
+
options.strictSSL = (_a = options.strictSSL) !== null && _a !== void 0 ? _a : strictSSL;
|
|
48
|
+
const agent = options.agent ? options.agent : (0, proxy_1.getProxyAgent)(options.url || '', process.env, {
|
|
49
|
+
proxyUrl: await this.getProxyUrl(options.url),
|
|
50
|
+
strictSSL: options.strictSSL
|
|
51
|
+
});
|
|
52
|
+
options.agent = agent;
|
|
53
|
+
const authorization = options.proxyAuthorization || this.authorization;
|
|
54
|
+
if (authorization) {
|
|
55
|
+
options.headers = {
|
|
56
|
+
...(options.headers || {}),
|
|
57
|
+
'Proxy-Authorization': authorization
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
options.headers = {
|
|
61
|
+
'Accept-Encoding': 'gzip',
|
|
62
|
+
...(options.headers || {}),
|
|
63
|
+
};
|
|
64
|
+
return options;
|
|
65
|
+
}
|
|
66
|
+
request(options, token) {
|
|
67
|
+
return new Promise(async (resolve, reject) => {
|
|
68
|
+
options = await this.processOptions(options);
|
|
69
|
+
const endpoint = new URL(options.url);
|
|
70
|
+
const rawRequest = options.getRawRequest
|
|
71
|
+
? options.getRawRequest(options)
|
|
72
|
+
: this.getNodeRequest(options);
|
|
73
|
+
const opts = {
|
|
74
|
+
hostname: endpoint.hostname,
|
|
75
|
+
port: endpoint.port ? parseInt(endpoint.port) : (endpoint.protocol === 'https:' ? 443 : 80),
|
|
76
|
+
protocol: endpoint.protocol,
|
|
77
|
+
path: endpoint.pathname + endpoint.search,
|
|
78
|
+
method: options.type || 'GET',
|
|
79
|
+
headers: options.headers,
|
|
80
|
+
agent: options.agent,
|
|
81
|
+
rejectUnauthorized: !!options.strictSSL
|
|
82
|
+
};
|
|
83
|
+
if (options.user && options.password) {
|
|
84
|
+
opts.auth = options.user + ':' + options.password;
|
|
85
|
+
}
|
|
86
|
+
const req = rawRequest(opts, async (res) => {
|
|
87
|
+
var _a;
|
|
88
|
+
const followRedirects = (_a = options.followRedirects) !== null && _a !== void 0 ? _a : 3;
|
|
89
|
+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && followRedirects > 0 && res.headers.location) {
|
|
90
|
+
this.request({
|
|
91
|
+
...options,
|
|
92
|
+
url: res.headers.location,
|
|
93
|
+
followRedirects: followRedirects - 1
|
|
94
|
+
}, token).then(resolve, reject);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const chunks = [];
|
|
98
|
+
const stream = res.headers['content-encoding'] === 'gzip' ? res.pipe((0, zlib_1.createGunzip)()) : res;
|
|
99
|
+
stream.on('data', chunk => {
|
|
100
|
+
chunks.push(chunk);
|
|
101
|
+
});
|
|
102
|
+
stream.on('end', () => {
|
|
103
|
+
const buffer = Buffer.concat(chunks);
|
|
104
|
+
resolve({
|
|
105
|
+
url: options.url,
|
|
106
|
+
res: {
|
|
107
|
+
headers: res.headers,
|
|
108
|
+
statusCode: res.statusCode
|
|
109
|
+
},
|
|
110
|
+
buffer
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
stream.on('error', reject);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
req.on('error', reject);
|
|
117
|
+
if (options.timeout) {
|
|
118
|
+
req.setTimeout(options.timeout);
|
|
119
|
+
}
|
|
120
|
+
if (options.data) {
|
|
121
|
+
req.write(options.data);
|
|
122
|
+
}
|
|
123
|
+
req.end();
|
|
124
|
+
token === null || token === void 0 ? void 0 : token.onCancellationRequested(() => {
|
|
125
|
+
req.abort();
|
|
126
|
+
reject();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async resolveProxy(url) {
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.NodeRequestService = NodeRequestService;
|
|
135
135
|
//# sourceMappingURL=node-request-service.js.map
|
package/lib/package.spec.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
16
|
//# sourceMappingURL=package.spec.d.ts.map
|
package/lib/package.spec.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
/* note: this bogus test file is required so that
|
|
17
|
-
we are able to run mocha unit tests on this
|
|
18
|
-
package, without having any actual unit tests in it.
|
|
19
|
-
This way a coverage report will be generated,
|
|
20
|
-
showing 0% coverage, instead of no report.
|
|
21
|
-
This file can be removed once we have real unit
|
|
22
|
-
tests in place. */
|
|
23
|
-
describe('request package', () => {
|
|
24
|
-
it('should support code coverage statistics', () => true);
|
|
25
|
-
});
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
/* note: this bogus test file is required so that
|
|
17
|
+
we are able to run mocha unit tests on this
|
|
18
|
+
package, without having any actual unit tests in it.
|
|
19
|
+
This way a coverage report will be generated,
|
|
20
|
+
showing 0% coverage, instead of no report.
|
|
21
|
+
This file can be removed once we have real unit
|
|
22
|
+
tests in place. */
|
|
23
|
+
describe('request package', () => {
|
|
24
|
+
it('should support code coverage statistics', () => true);
|
|
25
|
+
});
|
|
26
26
|
//# sourceMappingURL=package.spec.js.map
|
package/lib/proxy.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
-
*
|
|
4
|
-
* This program and the accompanying materials are made available under the
|
|
5
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
*
|
|
8
|
-
* This Source Code may also be made available under the following Secondary
|
|
9
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
* with the GNU Classpath Exception which is available at
|
|
12
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
*
|
|
14
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
********************************************************************************/
|
|
16
|
-
import * as httpAgent from 'http-proxy-agent';
|
|
17
|
-
import * as httpsAgent from 'https-proxy-agent';
|
|
18
|
-
export declare type ProxyAgent = httpAgent.HttpProxyAgent | httpsAgent.HttpsProxyAgent;
|
|
19
|
-
export interface ProxySettings {
|
|
20
|
-
proxyUrl?: string;
|
|
21
|
-
strictSSL?: boolean;
|
|
22
|
-
}
|
|
23
|
-
export declare function getProxyAgent(rawRequestURL: string, env: typeof process.env, options?: ProxySettings): ProxyAgent | undefined;
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
import * as httpAgent from 'http-proxy-agent';
|
|
17
|
+
import * as httpsAgent from 'https-proxy-agent';
|
|
18
|
+
export declare type ProxyAgent = httpAgent.HttpProxyAgent | httpsAgent.HttpsProxyAgent;
|
|
19
|
+
export interface ProxySettings {
|
|
20
|
+
proxyUrl?: string;
|
|
21
|
+
strictSSL?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function getProxyAgent(rawRequestURL: string, env: typeof process.env, options?: ProxySettings): ProxyAgent | undefined;
|
|
24
24
|
//# sourceMappingURL=proxy.d.ts.map
|
package/lib/proxy.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/********************************************************************************
|
|
3
|
-
* Copyright (C) 2022 TypeFox and others.
|
|
4
|
-
*
|
|
5
|
-
* This program and the accompanying materials are made available under the
|
|
6
|
-
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
*
|
|
9
|
-
* This Source Code may also be made available under the following Secondary
|
|
10
|
-
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
* with the GNU Classpath Exception which is available at
|
|
13
|
-
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
*
|
|
15
|
-
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
********************************************************************************/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getProxyAgent = void 0;
|
|
19
|
-
const url_1 = require("url");
|
|
20
|
-
const httpAgent = require("http-proxy-agent");
|
|
21
|
-
const httpsAgent = require("https-proxy-agent");
|
|
22
|
-
function getSystemProxyURI(requestURL, env) {
|
|
23
|
-
if (requestURL.protocol === 'http:') {
|
|
24
|
-
return env.HTTP_PROXY || env.http_proxy;
|
|
25
|
-
}
|
|
26
|
-
else if (requestURL.protocol === 'https:') {
|
|
27
|
-
return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
|
|
28
|
-
}
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
function getProxyAgent(rawRequestURL, env, options = {}) {
|
|
32
|
-
const requestURL = (0, url_1.parse)(rawRequestURL);
|
|
33
|
-
const proxyURL = options.proxyUrl || getSystemProxyURI(requestURL, env);
|
|
34
|
-
if (!proxyURL) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
const proxyEndpoint = (0, url_1.parse)(proxyURL);
|
|
38
|
-
if (!/^https?:$/.test(proxyEndpoint.protocol || '')) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
const opts = {
|
|
42
|
-
host: proxyEndpoint.hostname || '',
|
|
43
|
-
port: proxyEndpoint.port || (proxyEndpoint.protocol === 'https' ? '443' : '80'),
|
|
44
|
-
auth: proxyEndpoint.auth,
|
|
45
|
-
rejectUnauthorized: !!options.strictSSL,
|
|
46
|
-
};
|
|
47
|
-
const createAgent = requestURL.protocol === 'http:' ? httpAgent : httpsAgent;
|
|
48
|
-
return createAgent(opts);
|
|
49
|
-
}
|
|
50
|
-
exports.getProxyAgent = getProxyAgent;
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (C) 2022 TypeFox and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getProxyAgent = void 0;
|
|
19
|
+
const url_1 = require("url");
|
|
20
|
+
const httpAgent = require("http-proxy-agent");
|
|
21
|
+
const httpsAgent = require("https-proxy-agent");
|
|
22
|
+
function getSystemProxyURI(requestURL, env) {
|
|
23
|
+
if (requestURL.protocol === 'http:') {
|
|
24
|
+
return env.HTTP_PROXY || env.http_proxy;
|
|
25
|
+
}
|
|
26
|
+
else if (requestURL.protocol === 'https:') {
|
|
27
|
+
return env.HTTPS_PROXY || env.https_proxy || env.HTTP_PROXY || env.http_proxy;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function getProxyAgent(rawRequestURL, env, options = {}) {
|
|
32
|
+
const requestURL = (0, url_1.parse)(rawRequestURL);
|
|
33
|
+
const proxyURL = options.proxyUrl || getSystemProxyURI(requestURL, env);
|
|
34
|
+
if (!proxyURL) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
const proxyEndpoint = (0, url_1.parse)(proxyURL);
|
|
38
|
+
if (!/^https?:$/.test(proxyEndpoint.protocol || '')) {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
const opts = {
|
|
42
|
+
host: proxyEndpoint.hostname || '',
|
|
43
|
+
port: proxyEndpoint.port || (proxyEndpoint.protocol === 'https' ? '443' : '80'),
|
|
44
|
+
auth: proxyEndpoint.auth,
|
|
45
|
+
rejectUnauthorized: !!options.strictSSL,
|
|
46
|
+
};
|
|
47
|
+
const createAgent = requestURL.protocol === 'http:' ? httpAgent : httpsAgent;
|
|
48
|
+
return createAgent(opts);
|
|
49
|
+
}
|
|
50
|
+
exports.getProxyAgent = getProxyAgent;
|
|
51
51
|
//# sourceMappingURL=proxy.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/request",
|
|
3
|
-
"version": "1.48.
|
|
3
|
+
"version": "1.48.2",
|
|
4
4
|
"description": "Theia Proxy-Aware Request Service",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"https-proxy-agent": "^5.0.0",
|
|
34
34
|
"tslib": "^2.6.2"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "0e9583d043dde303de7a0f86f68439659f8827b0"
|
|
37
37
|
}
|