@actions/http-client
Advanced tools
Comparing version 1.0.0 to 1.0.1
125
index.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -57,3 +48,3 @@ const url = require("url"); | ||
readBody() { | ||
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
return new Promise(async (resolve, reject) => { | ||
let output = Buffer.alloc(0); | ||
@@ -66,3 +57,3 @@ this.message.on('data', (chunk) => { | ||
}); | ||
})); | ||
}); | ||
} | ||
@@ -143,66 +134,64 @@ } | ||
*/ | ||
request(verb, requestUrl, data, headers) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._disposed) { | ||
throw new Error("Client has already been disposed."); | ||
} | ||
let parsedUrl = url.parse(requestUrl); | ||
let info = this._prepareRequest(verb, parsedUrl, headers); | ||
// Only perform retries on reads since writes may not be idempotent. | ||
let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1; | ||
let numTries = 0; | ||
let response; | ||
while (numTries < maxTries) { | ||
response = yield this.requestRaw(info, data); | ||
// Check if it's an authentication challenge | ||
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) { | ||
let authenticationHandler; | ||
for (let i = 0; i < this.handlers.length; i++) { | ||
if (this.handlers[i].canHandleAuthentication(response)) { | ||
authenticationHandler = this.handlers[i]; | ||
break; | ||
} | ||
} | ||
if (authenticationHandler) { | ||
return authenticationHandler.handleAuthentication(this, info, data); | ||
} | ||
else { | ||
// We have received an unauthorized response but have no handlers to handle it. | ||
// Let the response return to the caller. | ||
return response; | ||
} | ||
} | ||
let redirectsRemaining = this._maxRedirects; | ||
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 | ||
&& this._allowRedirects | ||
&& redirectsRemaining > 0) { | ||
const redirectUrl = response.message.headers["location"]; | ||
if (!redirectUrl) { | ||
// if there's no location to redirect to, we won't | ||
async request(verb, requestUrl, data, headers) { | ||
if (this._disposed) { | ||
throw new Error("Client has already been disposed."); | ||
} | ||
let parsedUrl = url.parse(requestUrl); | ||
let info = this._prepareRequest(verb, parsedUrl, headers); | ||
// Only perform retries on reads since writes may not be idempotent. | ||
let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1; | ||
let numTries = 0; | ||
let response; | ||
while (numTries < maxTries) { | ||
response = await this.requestRaw(info, data); | ||
// Check if it's an authentication challenge | ||
if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) { | ||
let authenticationHandler; | ||
for (let i = 0; i < this.handlers.length; i++) { | ||
if (this.handlers[i].canHandleAuthentication(response)) { | ||
authenticationHandler = this.handlers[i]; | ||
break; | ||
} | ||
let parsedRedirectUrl = url.parse(redirectUrl); | ||
if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) { | ||
throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true."); | ||
} | ||
// we need to finish reading the response before reassigning response | ||
// which will leak the open socket. | ||
yield response.readBody(); | ||
// let's make the request with the new redirectUrl | ||
info = this._prepareRequest(verb, parsedRedirectUrl, headers); | ||
response = yield this.requestRaw(info, data); | ||
redirectsRemaining--; | ||
} | ||
if (HttpResponseRetryCodes.indexOf(response.message.statusCode) == -1) { | ||
// If not a retry code, return immediately instead of retrying | ||
if (authenticationHandler) { | ||
return authenticationHandler.handleAuthentication(this, info, data); | ||
} | ||
else { | ||
// We have received an unauthorized response but have no handlers to handle it. | ||
// Let the response return to the caller. | ||
return response; | ||
} | ||
numTries += 1; | ||
if (numTries < maxTries) { | ||
yield response.readBody(); | ||
yield this._performExponentialBackoff(numTries); | ||
} | ||
let redirectsRemaining = this._maxRedirects; | ||
while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 | ||
&& this._allowRedirects | ||
&& redirectsRemaining > 0) { | ||
const redirectUrl = response.message.headers["location"]; | ||
if (!redirectUrl) { | ||
// if there's no location to redirect to, we won't | ||
break; | ||
} | ||
let parsedRedirectUrl = url.parse(redirectUrl); | ||
if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) { | ||
throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true."); | ||
} | ||
// we need to finish reading the response before reassigning response | ||
// which will leak the open socket. | ||
await response.readBody(); | ||
// let's make the request with the new redirectUrl | ||
info = this._prepareRequest(verb, parsedRedirectUrl, headers); | ||
response = await this.requestRaw(info, data); | ||
redirectsRemaining--; | ||
} | ||
return response; | ||
}); | ||
if (HttpResponseRetryCodes.indexOf(response.message.statusCode) == -1) { | ||
// If not a retry code, return immediately instead of retrying | ||
return response; | ||
} | ||
numTries += 1; | ||
if (numTries < maxTries) { | ||
await response.readBody(); | ||
await this._performExponentialBackoff(numTries); | ||
} | ||
} | ||
return response; | ||
} | ||
@@ -209,0 +198,0 @@ /** |
{ | ||
"name": "@actions/http-client", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Actions Http Client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -16,4 +16,5 @@ | ||
- Typings included so no need to acquire separately (great for intellisense and no versioning drift) | ||
- [Proxy support](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/about-self-hosted-runners#using-a-proxy-server-with-self-hosted-runners) just works with actions and the runner | ||
- Targets ES2019 (runner runs actions with node 12+). Only supported on node 12+. | ||
- Basic, Bearer and PAT Support out of the box. Extensible handlers for others. | ||
- Proxy support, just works with actions and the runner | ||
- Redirects supported | ||
@@ -20,0 +21,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74
63433
626