@azure/core-rest-pipeline
Advanced tools
Comparing version 1.0.1-alpha.20210317.1 to 1.0.1
# Release History | ||
## 1.0.1 (Unreleased) | ||
## 1.0.1 (2021-03-18) | ||
- Fixed an issue where `timeout` and `abortSignal` of requests was not honored on Node after requests had already been issued to the server. [PR 14359](https://github.com/Azure/azure-sdk-for-js/pull/14359) | ||
@@ -6,0 +7,0 @@ ## 1.0.0 (2021-03-15) |
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
import { __awaiter } from "tslib"; | ||
import * as http from "http"; | ||
import * as https from "https"; | ||
@@ -8,2 +9,3 @@ import * as zlib from "zlib"; | ||
import { HttpsProxyAgent } from "https-proxy-agent"; | ||
import { HttpProxyAgent } from "http-proxy-agent"; | ||
import { AbortController, AbortError } from "@azure/abort-controller"; | ||
@@ -99,4 +101,3 @@ import { createHttpHeaders } from "./httpHeaders"; | ||
} | ||
const options = this.getRequestOptions(request); | ||
const req = https.request(options, (res) => __awaiter(this, void 0, void 0, function* () { | ||
const req = this.makeRequest(request, (res) => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
@@ -130,6 +131,4 @@ const headers = getResponseHeaders(res); | ||
abortController.signal.addEventListener("abort", () => { | ||
if (!req.finished) { | ||
req.abort(); | ||
reject(new AbortError("The operation was aborted.")); | ||
} | ||
req.abort(); | ||
reject(new AbortError("The operation was aborted.")); | ||
}); | ||
@@ -173,3 +172,44 @@ if (body && isReadableStream(body)) { | ||
} | ||
getOrCreateAgent(request) { | ||
makeRequest(request, callback) { | ||
const url = new URL(request.url); | ||
const isInsecure = url.protocol !== "https:"; | ||
if (isInsecure && !request.allowInsecureConnection) { | ||
throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`); | ||
} | ||
const agent = this.getOrCreateAgent(request, isInsecure); | ||
const options = { | ||
agent, | ||
hostname: url.hostname, | ||
path: `${url.pathname}${url.search}`, | ||
port: url.port, | ||
method: request.method, | ||
headers: request.headers.toJSON() | ||
}; | ||
if (isInsecure) { | ||
return http.request(options, callback); | ||
} | ||
else { | ||
return https.request(options, callback); | ||
} | ||
} | ||
getProxyAgentOptions(proxySettings, requestHeaders) { | ||
let parsedProxyUrl; | ||
try { | ||
parsedProxyUrl = new URL(proxySettings.host); | ||
} | ||
catch (_error) { | ||
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`); | ||
} | ||
const proxyAgentOptions = { | ||
hostname: parsedProxyUrl.hostname, | ||
port: proxySettings.port, | ||
protocol: parsedProxyUrl.protocol, | ||
headers: requestHeaders.toJSON() | ||
}; | ||
if (proxySettings.username && proxySettings.password) { | ||
proxyAgentOptions.auth = `${proxySettings.username}:${proxySettings.password}`; | ||
} | ||
return proxyAgentOptions; | ||
} | ||
getOrCreateAgent(request, isInsecure) { | ||
// At the moment, proxy settings and keepAlive are mutually | ||
@@ -180,31 +220,36 @@ // exclusive because the proxy library currently lacks the | ||
if (proxySettings) { | ||
if (!this.proxyAgent) { | ||
let parsedUrl; | ||
try { | ||
parsedUrl = new URL(proxySettings.host); | ||
if (isInsecure) { | ||
if (!this.httpProxyAgent) { | ||
const proxyAgentOptions = this.getProxyAgentOptions(proxySettings, request.headers); | ||
this.httpProxyAgent = new HttpProxyAgent(proxyAgentOptions); | ||
} | ||
catch (_error) { | ||
throw new Error(`Expecting a valid host string in proxy settings, but found "${proxySettings.host}".`); | ||
return this.httpProxyAgent; | ||
} | ||
else { | ||
if (!this.httpsProxyAgent) { | ||
const proxyAgentOptions = this.getProxyAgentOptions(proxySettings, request.headers); | ||
this.httpsProxyAgent = new HttpsProxyAgent(proxyAgentOptions); | ||
} | ||
const proxyAgentOptions = { | ||
hostname: parsedUrl.hostname, | ||
port: proxySettings.port, | ||
protocol: parsedUrl.protocol, | ||
headers: request.headers.toJSON() | ||
}; | ||
if (proxySettings.username && proxySettings.password) { | ||
proxyAgentOptions.auth = `${proxySettings.username}:${proxySettings.password}`; | ||
} | ||
this.proxyAgent = new HttpsProxyAgent(proxyAgentOptions); | ||
return this.httpsProxyAgent; | ||
} | ||
return this.proxyAgent; | ||
} | ||
else if (!request.disableKeepAlive) { | ||
if (!this.keepAliveAgent) { | ||
this.keepAliveAgent = new https.Agent({ | ||
else if (!request.disableKeepAlive && !isInsecure) { | ||
if (!this.httpsKeepAliveAgent) { | ||
this.httpsKeepAliveAgent = new https.Agent({ | ||
keepAlive: true | ||
}); | ||
} | ||
return this.keepAliveAgent; | ||
return this.httpsKeepAliveAgent; | ||
} | ||
else if (!request.disableKeepAlive && isInsecure) { | ||
if (!this.httpKeepAliveAgent) { | ||
this.httpKeepAliveAgent = new http.Agent({ | ||
keepAlive: true | ||
}); | ||
} | ||
return this.httpKeepAliveAgent; | ||
} | ||
else if (isInsecure) { | ||
return http.globalAgent; | ||
} | ||
else { | ||
@@ -214,15 +259,2 @@ return https.globalAgent; | ||
} | ||
getRequestOptions(request) { | ||
const agent = this.getOrCreateAgent(request); | ||
const url = new URL(request.url); | ||
const options = { | ||
agent, | ||
hostname: url.hostname, | ||
path: `${url.pathname}${url.search}`, | ||
port: url.port, | ||
method: request.method, | ||
headers: request.headers.toJSON() | ||
}; | ||
return options; | ||
} | ||
} | ||
@@ -229,0 +261,0 @@ function getResponseHeaders(res) { |
@@ -7,3 +7,3 @@ // Copyright (c) Microsoft Corporation. | ||
constructor(options) { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f; | ||
this.url = options.url; | ||
@@ -24,2 +24,3 @@ this.body = options.body; | ||
this.requestId = options.requestId || generateUuid(); | ||
this.allowInsecureConnection = (_f = options.allowInsecureConnection) !== null && _f !== void 0 ? _f : false; | ||
} | ||
@@ -26,0 +27,0 @@ } |
@@ -23,2 +23,7 @@ // Copyright (c) Microsoft Corporation. | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = new URL(request.url); | ||
const isInsecure = url.protocol !== "https:"; | ||
if (isInsecure && !request.allowInsecureConnection) { | ||
throw new Error(`Cannot connect to ${request.url} while allowInsecureConnection is false.`); | ||
} | ||
const xhr = new XMLHttpRequest(); | ||
@@ -25,0 +30,0 @@ if (request.proxySettings) { |
{ | ||
"name": "@azure/core-rest-pipeline", | ||
"version": "1.0.1-alpha.20210317.1", | ||
"version": "1.0.1", | ||
"description": "Isomorphic client library for making HTTP requests in node.js and browser.", | ||
@@ -96,3 +96,3 @@ "sdk-type": "client", | ||
"@azure/core-auth": "^1.2.0", | ||
"@azure/core-tracing": "^1.0.0-alpha", | ||
"@azure/core-tracing": "1.0.0-preview.10", | ||
"@azure/logger": "^1.0.0", | ||
@@ -102,2 +102,3 @@ "@opentelemetry/api": "^0.10.2", | ||
"tslib": "^2.0.0", | ||
"http-proxy-agent": "^4.0.1", | ||
"https-proxy-agent": "^5.0.0", | ||
@@ -118,3 +119,3 @@ "uuid": "^8.3.0" | ||
"@types/uuid": "^8.0.0", | ||
"@azure/eslint-plugin-azure-sdk": "^3.0.0-alpha", | ||
"@azure/eslint-plugin-azure-sdk": "^3.0.0", | ||
"chai": "^4.2.0", | ||
@@ -121,0 +122,0 @@ "downlevel-dts": "~0.4.0", |
@@ -384,2 +384,4 @@ /// <reference types="node" /> | ||
onDownloadProgress?: (progress: TransferProgressEvent) => void; | ||
/** Set to true if the request is sent over HTTP instead of HTTPS */ | ||
allowInsecureConnection?: boolean; | ||
} | ||
@@ -452,2 +454,4 @@ /** | ||
onDownloadProgress?: (progress: TransferProgressEvent) => void; | ||
/** Set to true if the request is sent over HTTP instead of HTTPS */ | ||
allowInsecureConnection?: boolean; | ||
} | ||
@@ -454,0 +458,0 @@ /** |
@@ -417,2 +417,4 @@ /// <reference types="node" /> | ||
onDownloadProgress?: (progress: TransferProgressEvent) => void; | ||
/** Set to true if the request is sent over HTTP instead of HTTPS */ | ||
allowInsecureConnection?: boolean; | ||
} | ||
@@ -486,2 +488,4 @@ | ||
onDownloadProgress?: (progress: TransferProgressEvent) => void; | ||
/** Set to true if the request is sent over HTTP instead of HTTPS */ | ||
allowInsecureConnection?: boolean; | ||
} | ||
@@ -488,0 +492,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Network access
Supply chain riskThis module accesses the network.
Found 2 instances 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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
492503
5304
0
10
8
+ Addedhttp-proxy-agent@^4.0.1
+ Added@azure/core-tracing@1.0.0-preview.10(transitive)
+ Added@opencensus/web-types@0.0.7(transitive)
+ Added@tootallnate/once@1.1.2(transitive)
+ Addedhttp-proxy-agent@4.0.1(transitive)
- Removed@azure/core-tracing@1.2.0(transitive)