@actions/http-client 1.0.9 → 2.0.0
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 +13 -19
- package/lib/auth.d.ts +26 -0
- package/lib/auth.js +81 -0
- package/lib/auth.js.map +1 -0
- package/{index.d.ts → lib/index.d.ts} +21 -22
- package/lib/index.js +605 -0
- package/lib/index.js.map +1 -0
- package/lib/interfaces.d.ts +44 -0
- package/{interfaces.js → lib/interfaces.js} +1 -0
- package/lib/interfaces.js.map +1 -0
- package/{proxy.d.ts → lib/proxy.d.ts} +0 -0
- package/{proxy.js → lib/proxy.js} +18 -14
- package/lib/proxy.js.map +1 -0
- package/package.json +32 -25
- package/RELEASES.md +0 -22
- package/actions.png +0 -0
- package/auth.d.ts +0 -23
- package/auth.js +0 -58
- package/index.js +0 -535
- package/interfaces.d.ts +0 -49
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import * as https from 'https';
|
|
4
|
+
import { HttpClientResponse } from './index';
|
|
5
|
+
export interface HttpClient {
|
|
6
|
+
options(requestUrl: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
7
|
+
get(requestUrl: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
8
|
+
del(requestUrl: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
9
|
+
post(requestUrl: string, data: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
10
|
+
patch(requestUrl: string, data: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
11
|
+
put(requestUrl: string, data: string, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
12
|
+
sendStream(verb: string, requestUrl: string, stream: NodeJS.ReadableStream, additionalHeaders?: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
13
|
+
request(verb: string, requestUrl: string, data: string | NodeJS.ReadableStream, headers: http.OutgoingHttpHeaders): Promise<HttpClientResponse>;
|
|
14
|
+
requestRaw(info: RequestInfo, data: string | NodeJS.ReadableStream): Promise<HttpClientResponse>;
|
|
15
|
+
requestRawWithCallback(info: RequestInfo, data: string | NodeJS.ReadableStream, onResult: (err?: Error, res?: HttpClientResponse) => void): void;
|
|
16
|
+
}
|
|
17
|
+
export interface RequestHandler {
|
|
18
|
+
prepareRequest(options: http.RequestOptions): void;
|
|
19
|
+
canHandleAuthentication(response: HttpClientResponse): boolean;
|
|
20
|
+
handleAuthentication(httpClient: HttpClient, requestInfo: RequestInfo, data: string | NodeJS.ReadableStream | null): Promise<HttpClientResponse>;
|
|
21
|
+
}
|
|
22
|
+
export interface RequestInfo {
|
|
23
|
+
options: http.RequestOptions;
|
|
24
|
+
parsedUrl: URL;
|
|
25
|
+
httpModule: typeof http | typeof https;
|
|
26
|
+
}
|
|
27
|
+
export interface RequestOptions {
|
|
28
|
+
headers?: http.OutgoingHttpHeaders;
|
|
29
|
+
socketTimeout?: number;
|
|
30
|
+
ignoreSslError?: boolean;
|
|
31
|
+
allowRedirects?: boolean;
|
|
32
|
+
allowRedirectDowngrade?: boolean;
|
|
33
|
+
maxRedirects?: number;
|
|
34
|
+
maxSockets?: number;
|
|
35
|
+
keepAlive?: boolean;
|
|
36
|
+
deserializeDates?: boolean;
|
|
37
|
+
allowRetries?: boolean;
|
|
38
|
+
maxRetries?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface TypedResponse<T> {
|
|
41
|
+
statusCode: number;
|
|
42
|
+
result: T | null;
|
|
43
|
+
headers: http.IncomingHttpHeaders;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkBypass = exports.getProxyUrl = void 0;
|
|
3
4
|
function getProxyUrl(reqUrl) {
|
|
4
|
-
|
|
5
|
-
let proxyUrl;
|
|
5
|
+
const usingSsl = reqUrl.protocol === 'https:';
|
|
6
6
|
if (checkBypass(reqUrl)) {
|
|
7
|
-
return
|
|
7
|
+
return undefined;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const proxyVar = (() => {
|
|
10
|
+
if (usingSsl) {
|
|
11
|
+
return process.env['https_proxy'] || process.env['HTTPS_PROXY'];
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return process.env['http_proxy'] || process.env['HTTP_PROXY'];
|
|
15
|
+
}
|
|
16
|
+
})();
|
|
17
|
+
if (proxyVar) {
|
|
18
|
+
return new URL(proxyVar);
|
|
12
19
|
}
|
|
13
20
|
else {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
if (proxyVar) {
|
|
17
|
-
proxyUrl = new URL(proxyVar);
|
|
21
|
+
return undefined;
|
|
18
22
|
}
|
|
19
|
-
return proxyUrl;
|
|
20
23
|
}
|
|
21
24
|
exports.getProxyUrl = getProxyUrl;
|
|
22
25
|
function checkBypass(reqUrl) {
|
|
23
26
|
if (!reqUrl.hostname) {
|
|
24
27
|
return false;
|
|
25
28
|
}
|
|
26
|
-
|
|
29
|
+
const noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || '';
|
|
27
30
|
if (!noProxy) {
|
|
28
31
|
return false;
|
|
29
32
|
}
|
|
@@ -39,12 +42,12 @@ function checkBypass(reqUrl) {
|
|
|
39
42
|
reqPort = 443;
|
|
40
43
|
}
|
|
41
44
|
// Format the request hostname and hostname with port
|
|
42
|
-
|
|
45
|
+
const upperReqHosts = [reqUrl.hostname.toUpperCase()];
|
|
43
46
|
if (typeof reqPort === 'number') {
|
|
44
47
|
upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`);
|
|
45
48
|
}
|
|
46
49
|
// Compare request host against noproxy
|
|
47
|
-
for (
|
|
50
|
+
for (const upperNoProxyItem of noProxy
|
|
48
51
|
.split(',')
|
|
49
52
|
.map(x => x.trim().toUpperCase())
|
|
50
53
|
.filter(x => x)) {
|
|
@@ -55,3 +58,4 @@ function checkBypass(reqUrl) {
|
|
|
55
58
|
return false;
|
|
56
59
|
}
|
|
57
60
|
exports.checkBypass = checkBypass;
|
|
61
|
+
//# sourceMappingURL=proxy.js.map
|
package/lib/proxy.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,MAAW;IACrC,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,KAAK,QAAQ,CAAA;IAE7C,IAAI,WAAW,CAAC,MAAM,CAAC,EAAE;QACvB,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE;QACrB,IAAI,QAAQ,EAAE;YACZ,OAAO,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;SAChE;aAAM;YACL,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;SAC9D;IACH,CAAC,CAAC,EAAE,CAAA;IAEJ,IAAI,QAAQ,EAAE;QACZ,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAA;KACzB;SAAM;QACL,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AApBD,kCAoBC;AAED,SAAgB,WAAW,CAAC,MAAW;IACrC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;QACpB,OAAO,KAAK,CAAA;KACb;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,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
5
|
-
"
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"github",
|
|
7
|
+
"actions",
|
|
8
|
+
"http"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/actions/toolkit/tree/main/packages/http-client",
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"main": "lib/index.js",
|
|
13
|
+
"types": "lib/index.d.ts",
|
|
14
|
+
"directories": {
|
|
15
|
+
"lib": "lib",
|
|
16
|
+
"test": "__tests__"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"lib",
|
|
20
|
+
"!.DS_Store"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
12
24
|
},
|
|
13
25
|
"repository": {
|
|
14
26
|
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/actions/
|
|
27
|
+
"url": "git+https://github.com/actions/toolkit.git",
|
|
28
|
+
"directory": "packages/github"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"audit-moderate": "npm install && npm audit --json --audit-level=moderate > audit.json",
|
|
32
|
+
"test": "echo \"Error: run tests from root\" && exit 1",
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"format": "prettier --write **/*.ts",
|
|
35
|
+
"format-check": "prettier --check **/*.ts",
|
|
36
|
+
"tsc": "tsc"
|
|
16
37
|
},
|
|
17
|
-
"keywords": [
|
|
18
|
-
"Actions",
|
|
19
|
-
"Http"
|
|
20
|
-
],
|
|
21
|
-
"author": "GitHub, Inc.",
|
|
22
|
-
"license": "MIT",
|
|
23
38
|
"bugs": {
|
|
24
|
-
"url": "https://github.com/actions/
|
|
39
|
+
"url": "https://github.com/actions/toolkit/issues"
|
|
25
40
|
},
|
|
26
|
-
"homepage": "https://github.com/actions/http-client#readme",
|
|
27
41
|
"devDependencies": {
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/node": "^12.12.31",
|
|
30
|
-
"jest": "^25.1.0",
|
|
31
|
-
"prettier": "^2.0.4",
|
|
42
|
+
"@types/tunnel": "0.0.3",
|
|
32
43
|
"proxy": "^1.0.1",
|
|
33
|
-
"ts-jest": "^25.2.1",
|
|
34
|
-
"typescript": "^3.8.3"
|
|
35
|
-
},
|
|
36
|
-
"dependencies": {
|
|
37
44
|
"tunnel": "0.0.6"
|
|
38
45
|
}
|
|
39
46
|
}
|
package/RELEASES.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
## Releases
|
|
2
|
-
|
|
3
|
-
## 1.0.9
|
|
4
|
-
Throw HttpClientError instead of a generic Error from the \<verb>Json() helper methods when the server responds with a non-successful status code.
|
|
5
|
-
|
|
6
|
-
## 1.0.8
|
|
7
|
-
Fixed security issue where a redirect (e.g. 302) to another domain would pass headers. The fix was to strip the authorization header if the hostname was different. More [details in PR #27](https://github.com/actions/http-client/pull/27)
|
|
8
|
-
|
|
9
|
-
## 1.0.7
|
|
10
|
-
Update NPM dependencies and add 429 to the list of HttpCodes
|
|
11
|
-
|
|
12
|
-
## 1.0.6
|
|
13
|
-
Automatically sends Content-Type and Accept application/json headers for \<verb>Json() helper methods if not set in the client or parameters.
|
|
14
|
-
|
|
15
|
-
## 1.0.5
|
|
16
|
-
Adds \<verb>Json() helper methods for json over http scenarios.
|
|
17
|
-
|
|
18
|
-
## 1.0.4
|
|
19
|
-
Started to add \<verb>Json() helper methods. Do not use this release for that. Use >= 1.0.5 since there was an issue with types.
|
|
20
|
-
|
|
21
|
-
## 1.0.1 to 1.0.3
|
|
22
|
-
Adds proxy support.
|
package/actions.png
DELETED
|
Binary file
|
package/auth.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import ifm = require('./interfaces');
|
|
2
|
-
export declare class BasicCredentialHandler implements ifm.IRequestHandler {
|
|
3
|
-
username: string;
|
|
4
|
-
password: string;
|
|
5
|
-
constructor(username: string, password: string);
|
|
6
|
-
prepareRequest(options: any): void;
|
|
7
|
-
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
8
|
-
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
9
|
-
}
|
|
10
|
-
export declare class BearerCredentialHandler implements ifm.IRequestHandler {
|
|
11
|
-
token: string;
|
|
12
|
-
constructor(token: string);
|
|
13
|
-
prepareRequest(options: any): void;
|
|
14
|
-
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
15
|
-
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
16
|
-
}
|
|
17
|
-
export declare class PersonalAccessTokenCredentialHandler implements ifm.IRequestHandler {
|
|
18
|
-
token: string;
|
|
19
|
-
constructor(token: string);
|
|
20
|
-
prepareRequest(options: any): void;
|
|
21
|
-
canHandleAuthentication(response: ifm.IHttpClientResponse): boolean;
|
|
22
|
-
handleAuthentication(httpClient: ifm.IHttpClient, requestInfo: ifm.IRequestInfo, objs: any): Promise<ifm.IHttpClientResponse>;
|
|
23
|
-
}
|
package/auth.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class BasicCredentialHandler {
|
|
4
|
-
constructor(username, password) {
|
|
5
|
-
this.username = username;
|
|
6
|
-
this.password = password;
|
|
7
|
-
}
|
|
8
|
-
prepareRequest(options) {
|
|
9
|
-
options.headers['Authorization'] =
|
|
10
|
-
'Basic ' +
|
|
11
|
-
Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
12
|
-
}
|
|
13
|
-
// This handler cannot handle 401
|
|
14
|
-
canHandleAuthentication(response) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
handleAuthentication(httpClient, requestInfo, objs) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.BasicCredentialHandler = BasicCredentialHandler;
|
|
22
|
-
class BearerCredentialHandler {
|
|
23
|
-
constructor(token) {
|
|
24
|
-
this.token = token;
|
|
25
|
-
}
|
|
26
|
-
// currently implements pre-authorization
|
|
27
|
-
// TODO: support preAuth = false where it hooks on 401
|
|
28
|
-
prepareRequest(options) {
|
|
29
|
-
options.headers['Authorization'] = 'Bearer ' + this.token;
|
|
30
|
-
}
|
|
31
|
-
// This handler cannot handle 401
|
|
32
|
-
canHandleAuthentication(response) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
handleAuthentication(httpClient, requestInfo, objs) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.BearerCredentialHandler = BearerCredentialHandler;
|
|
40
|
-
class PersonalAccessTokenCredentialHandler {
|
|
41
|
-
constructor(token) {
|
|
42
|
-
this.token = token;
|
|
43
|
-
}
|
|
44
|
-
// currently implements pre-authorization
|
|
45
|
-
// TODO: support preAuth = false where it hooks on 401
|
|
46
|
-
prepareRequest(options) {
|
|
47
|
-
options.headers['Authorization'] =
|
|
48
|
-
'Basic ' + Buffer.from('PAT:' + this.token).toString('base64');
|
|
49
|
-
}
|
|
50
|
-
// This handler cannot handle 401
|
|
51
|
-
canHandleAuthentication(response) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
handleAuthentication(httpClient, requestInfo, objs) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.PersonalAccessTokenCredentialHandler = PersonalAccessTokenCredentialHandler;
|