зеркало из https://github.com/Azure/ms-rest-js.git
Changes based on PR feedback
This commit is contained in:
Родитель
9bf26c4d45
Коммит
0ed18dc034
|
@ -48,11 +48,11 @@ var FetchHttpClient = /** @class */ (function () {
|
|||
}
|
||||
FetchHttpClient.prototype.send = function (request) {
|
||||
return __awaiter(this, void 0, void 0, function () {
|
||||
var result, fetchRequestOptions, fetchResponse_1, responseHeaders_1, fetchResponseHeaders, response, err_1;
|
||||
var _this = this;
|
||||
var fetchRequestOptions, fetchResponse, responseHeaders, fetchResponseHeaders;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
_a.trys.push([0, 2, , 3]);
|
||||
fetchRequestOptions = {
|
||||
method: request.httpMethod,
|
||||
headers: request.headers.toJson(),
|
||||
|
@ -60,24 +60,27 @@ var FetchHttpClient = /** @class */ (function () {
|
|||
};
|
||||
return [4 /*yield*/, fetch(request.url, fetchRequestOptions)];
|
||||
case 1:
|
||||
fetchResponse_1 = _a.sent();
|
||||
responseHeaders_1 = new httpHeaders_1.HttpHeaders();
|
||||
fetchResponseHeaders = fetchResponse_1.headers;
|
||||
fetchResponseHeaders.forEach(function (headerValue, headerName) { responseHeaders_1.set(headerName, headerValue); });
|
||||
response = {
|
||||
request: request,
|
||||
statusCode: fetchResponse_1.status,
|
||||
headers: responseHeaders_1,
|
||||
textBody: function () { return fetchResponse_1.text(); },
|
||||
deserializedBody: function () { return fetchResponse_1.json(); }
|
||||
};
|
||||
result = Promise.resolve(response);
|
||||
return [3 /*break*/, 3];
|
||||
case 2:
|
||||
err_1 = _a.sent();
|
||||
result = Promise.reject(err_1);
|
||||
return [3 /*break*/, 3];
|
||||
case 3: return [2 /*return*/, result];
|
||||
fetchResponse = _a.sent();
|
||||
responseHeaders = new httpHeaders_1.HttpHeaders();
|
||||
fetchResponseHeaders = fetchResponse.headers;
|
||||
fetchResponseHeaders.forEach(function (headerValue, headerName) { responseHeaders.set(headerName, headerValue); });
|
||||
return [2 /*return*/, {
|
||||
request: request,
|
||||
statusCode: fetchResponse.status,
|
||||
headers: responseHeaders,
|
||||
textBody: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fetchResponse.text()];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
}); }); },
|
||||
deserializedBody: function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, fetchResponse.json()];
|
||||
case 1: return [2 /*return*/, _a.sent()];
|
||||
}
|
||||
}); }); }
|
||||
}];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"fetchHttpClient.js","sourceRoot":"","sources":["../../lib/fetchHttpClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,6CAA4C;AAM5C;;GAEG;AACH,IAAM,KAAK,GAAgB,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC;AAEhF;;GAEG;AACH;IAAA;IAgCA,CAAC;IA/BgB,8BAAI,GAAjB,UAAkB,OAAoB;;;;;;;wBAIxB,mBAAmB,GAAgB;4BACrC,MAAM,EAAE,OAAO,CAAC,UAAU;4BAC1B,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE;4BACjC,IAAI,EAAE,OAAO,CAAC,IAAI;yBACrB,CAAC;wBAE8B,qBAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,mBAAmB,CAAC,EAAA;;wBAAvE,kBAA0B,SAA6C;wBAEvE,oBAAkB,IAAI,yBAAW,EAAE,CAAC;wBACpC,oBAAoB,GAAY,eAAa,CAAC,OAAO,CAAC;wBAC5D,oBAAoB,CAAC,OAAO,CAAC,UAAC,WAAmB,EAAE,UAAkB,IAAO,iBAAe,CA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AAoB,GAAY,aAAa,CAAC,OAAO,CAAC;wBAC5D,oBAAoB,CAAC,OAAO,CAAC,UAAC,WAAmB,EAAE,UAAkB,IAAO,eAAe,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;wBAE7H,sBAAO;gCACH,OAAO,EAAE,OAAO;gCAChB,UAAU,EAAE,aAAa,CAAC,MAAM;gCAChC,OAAO,EAAE,eAAe;gCACxB,QAAQ,EAAE;;gDAAY,qBAAM,aAAa,CAAC,IAAI,EAAE,EAAA;gDAA1B,sBAAA,SAA0B,EAAA;;yCAAA;gCAChD,gBAAgB,EAAE;;gDAAY,qBAAM,aAAa,CAAC,IAAI,EAAE,EAAA;gDAA1B,sBAAA,SAA0B,EAAA;;yCAAA;6BAC3D,EAAC;;;;KACL;IACL,sBAAC;AAAD,CAAC,AAtBD,IAsBC;AAtBY,0CAAe"}
|
|
@ -13,7 +13,7 @@ function getHeaderKey(headerName) {
|
|||
*/
|
||||
var HttpHeaders = /** @class */ (function () {
|
||||
function HttpHeaders(rawHeaders) {
|
||||
this.headersMap = {};
|
||||
this._headersMap = {};
|
||||
if (rawHeaders) {
|
||||
for (var headerName in rawHeaders) {
|
||||
this.set(headerName, rawHeaders[headerName]);
|
||||
|
@ -27,7 +27,7 @@ var HttpHeaders = /** @class */ (function () {
|
|||
* @param headerValue The value of the header to set.
|
||||
*/
|
||||
HttpHeaders.prototype.set = function (headerName, headerValue) {
|
||||
this.headersMap[getHeaderKey(headerName)] = { name: headerName, value: headerValue.toString() };
|
||||
this._headersMap[getHeaderKey(headerName)] = { name: headerName, value: headerValue.toString() };
|
||||
};
|
||||
/**
|
||||
* Get the header value for the provided header name, or undefined if no header exists in this
|
||||
|
@ -35,7 +35,7 @@ var HttpHeaders = /** @class */ (function () {
|
|||
* @param headerName The name of the header.
|
||||
*/
|
||||
HttpHeaders.prototype.get = function (headerName) {
|
||||
var header = this.headersMap[getHeaderKey(headerName)];
|
||||
var header = this._headersMap[getHeaderKey(headerName)];
|
||||
return !header ? undefined : header.value;
|
||||
};
|
||||
/**
|
||||
|
@ -43,8 +43,8 @@ var HttpHeaders = /** @class */ (function () {
|
|||
*/
|
||||
HttpHeaders.prototype.headers = function () {
|
||||
var headers = [];
|
||||
for (var headerKey in this.headersMap) {
|
||||
headers.push(this.headersMap[headerKey]);
|
||||
for (var headerKey in this._headersMap) {
|
||||
headers.push(this._headersMap[headerKey]);
|
||||
}
|
||||
return headers;
|
||||
};
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"httpHeaders.js","sourceRoot":"","sources":["../../lib/httpHeaders.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F;;GAEG;AACH,sBAAsB,UAAkB;IACpC,MAAM,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;AACpC,CAAC;AAsBD;;GAEG;AACH;IAGI,qBAAY,UAA2B;QACnC,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;YACb,GAAG,CAAC,CAAC,IAAM,UAAU,IAAI,UAAU,CAAC,CAAC,CAAC;gBAClC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC;YACjD,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACI,yBAAG,GAAV,UAAW,UAAkB,EAAE,WAA4B;QACvD,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC;IACpG,CAAC;IAED;;;;OAIG;IACI,yBAAG,GAAV,UAAW,UAAkB;QACzB,IAAM,MAAM,GAAe,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;QACrE,MAAM,CAAC,CAAC,MAAM,CAA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EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACtC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/C,CAAC;QAED,MAAM,CAAC,MAAM,CAAC;IAClB,CAAC;IACL,kBAAC;AAAD,CAAC,AAhFD,IAgFC;AAhFY,kCAAW"}
|
|
@ -16,17 +16,17 @@ function getDefaultHttpClient() {
|
|||
* be applied to a HTTP response when it is received.
|
||||
*/
|
||||
var HttpPipeline = /** @class */ (function () {
|
||||
function HttpPipeline(requestPolicyFactories, options) {
|
||||
this.requestPolicyFactories = requestPolicyFactories;
|
||||
this.options = options;
|
||||
if (!this.options) {
|
||||
this.options = {};
|
||||
function HttpPipeline(_requestPolicyFactories, _httpPipelineOptions) {
|
||||
this._requestPolicyFactories = _requestPolicyFactories;
|
||||
this._httpPipelineOptions = _httpPipelineOptions;
|
||||
if (!this._httpPipelineOptions) {
|
||||
this._httpPipelineOptions = {};
|
||||
}
|
||||
if (!this.options.httpClient) {
|
||||
this.options.httpClient = getDefaultHttpClient();
|
||||
if (!this._httpPipelineOptions.httpClient) {
|
||||
this._httpPipelineOptions.httpClient = getDefaultHttpClient();
|
||||
}
|
||||
this.httpClient = this.options.httpClient;
|
||||
this.requestPolicyOptions = new requestPolicyOptions_1.RequestPolicyOptions(this.options.pipelineLogger);
|
||||
this._httpClient = this._httpPipelineOptions.httpClient;
|
||||
this._requestPolicyOptions = new requestPolicyOptions_1.RequestPolicyOptions(this._httpPipelineOptions.pipelineLogger);
|
||||
}
|
||||
/**
|
||||
* Send the provided HttpRequest request.
|
||||
|
@ -34,12 +34,12 @@ var HttpPipeline = /** @class */ (function () {
|
|||
* @return A Promise that resolves to the HttpResponse from the targeted server.
|
||||
*/
|
||||
HttpPipeline.prototype.send = function (request) {
|
||||
var requestPolicyChainHead = this.httpClient;
|
||||
if (this.requestPolicyFactories) {
|
||||
var requestPolicyFactoriesLength = this.requestPolicyFactories.length;
|
||||
var requestPolicyChainHead = this._httpClient;
|
||||
if (this._requestPolicyFactories) {
|
||||
var requestPolicyFactoriesLength = this._requestPolicyFactories.length;
|
||||
for (var i = requestPolicyFactoriesLength - 1; i >= 0; --i) {
|
||||
var requestPolicyFactory = this.requestPolicyFactories[i];
|
||||
requestPolicyChainHead = requestPolicyFactory(requestPolicyChainHead, this.requestPolicyOptions);
|
||||
var requestPolicyFactory = this._requestPolicyFactories[i];
|
||||
requestPolicyChainHead = requestPolicyFactory(requestPolicyChainHead, this._requestPolicyOptions);
|
||||
}
|
||||
}
|
||||
return requestPolicyChainHead.send(request);
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"httpPipeline.js","sourceRoot":"","sources":["../../lib/httpPipeline.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,qDAAoD;AAOpD,+DAA8D;AAE9D,IAAI,iBAA6B,CAAC;AAElC;IACI,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACrB,iBAAiB,GAAG,IAAI,iCAAe,EAAE,CAAC;IAC9C,CAAC;IACD,MAAM,CAAC,iBAAiB,CAAC;AAC7B,CAAC;AAED;;;GAGG;AACH;IAII,sBAA6B,sBAA8C,EAAmB,OAA4B;QAA7F,2BAAsB,GAAtB,sBAAsB,CAAwB;QAAmB,YAAO,GAAP,OAAO,CAAqB;QACtH,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAChB,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QACtB,CAAC;QAED,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3B,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,oBAAoB,EAAE,CAAC;QACrD,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,O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oBAAoB,CAAqB;QACpI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,CAAC;YAC7B,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;QACnC,CAAC;QAED,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;YACxC,IAAI,CAAC,oBAAoB,CAAC,UAAU,GAAG,oBAAoB,EAAE,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,UAAU,CAAC;QACxD,IAAI,CAAC,qBAAqB,GAAG,IAAI,2CAAoB,CAAC,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;IACpG,CAAC;IAED;;;;OAIG;IACI,2BAAI,GAAX,UAAY,OAAoB;QAC5B,IAAI,sBAAsB,GAAkB,IAAI,CAAC,WAAW,CAAC;QAC7D,EAAE,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC;YAC/B,IAAM,4BAA4B,GAAW,IAAI,CAAC,uBAAuB,CAAC,MAAM,CAAC;YACjF,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,4BAA4B,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;gBACzD,IAAM,oBAAoB,GAAyB,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;gBACnF,sBAAsB,GAAG,oBAAoB,CAAC,sBAAsB,EAAE,IAAI,CAAC,qBAAqB,CAAC,CAAC;YACtG,CAAC;QACL,CAAC;QACD,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IACL,mBAAC;AAAD,CAAC,AAjCD,IAiCC;AAjCY,oCAAY"}
|
|
@ -2,6 +2,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var httpPipelineLogLevel_1 = require("./httpPipelineLogLevel");
|
||||
/**
|
||||
* A HttpPipelineLogger that will send its logs to the console.
|
||||
*/
|
||||
|
@ -21,7 +22,7 @@ var ConsoleHttpPipelineLogger = /** @class */ (function () {
|
|||
* provided message.
|
||||
*/
|
||||
ConsoleHttpPipelineLogger.prototype.log = function (logLevel, message) {
|
||||
console.log(logLevel + ": " + message);
|
||||
console.log(httpPipelineLogLevel_1.HttpPipelineLogLevel[logLevel] + ": " + message);
|
||||
};
|
||||
return ConsoleHttpPipelineLogger;
|
||||
}());
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"httpPipelineLogger.js","sourceRoot":"","sources":["../../lib/httpPipelineLogger.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAyB/F;;GAEG;AACH;IACI;;;OAGG;IACH,mCAAmB,eAAqC;QAArC,oBAAe,GAAf,eAAe,CAAsB;IACxD,CAAC;IAED;;;;;;OAMG;IACH,uCAAG,GAAH,UAAI,QAA8B,EAAE,OAAe;QAC/C,OAAO,CAAC,GAAG,CAAI,QAAQ,UAAK,OAAS,CAAC,CAAC;IAC3C,CAAC;IACL,gCAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,8DAAyB"}
|
||||
{"version":3,"file":"httpPipelineLogger.js","sourceRoot":"","sources":["../../lib/httpPipelineLogger.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,+DAA8D;AAuB9D;;GAEG;AACH;IACI;;;OAGG;IACH,mCAAmB,eAAqC;QAArC,oBAAe,GAAf,eAAe,CAAsB;IACxD,CAAC;IAED;;;;;;OAMG;IACH,uCAAG,GAAH,UAAI,QAA8B,EAAE,OAAe;QAC/C,OAAO,CAAC,GAAG,CAAI,2CAAoB,CAAC,QAAQ,CAAC,UAAK,OAAS,CAAC,CAAC;IACjE,CAAC;IACL,gCAAC;AAAD,CAAC,AAlBD,IAkBC;AAlBY,8DAAyB"}
|
|
@ -26,17 +26,17 @@ function userAgentPolicy(userAgent) {
|
|||
exports.userAgentPolicy = userAgentPolicy;
|
||||
var UserAgentPolicy = /** @class */ (function (_super) {
|
||||
__extends(UserAgentPolicy, _super);
|
||||
function UserAgentPolicy(userAgent, nextPolicy, options) {
|
||||
function UserAgentPolicy(_userAgent, nextPolicy, options) {
|
||||
var _this = _super.call(this, nextPolicy, options) || this;
|
||||
_this.userAgent = userAgent;
|
||||
_this._userAgent = _userAgent;
|
||||
return _this;
|
||||
}
|
||||
UserAgentPolicy.prototype.send = function (request) {
|
||||
if (this.shouldLog(httpPipelineLogLevel_1.HttpPipelineLogLevel.INFO)) {
|
||||
this.log(httpPipelineLogLevel_1.HttpPipelineLogLevel.INFO, "Set \"User-Agent\" header to \"" + this.userAgent + "\".");
|
||||
this.log(httpPipelineLogLevel_1.HttpPipelineLogLevel.INFO, "Set \"User-Agent\" header to \"" + this._userAgent + "\".");
|
||||
}
|
||||
request.headers.set("User-Agent", this.userAgent);
|
||||
return this.nextPolicy.send(request);
|
||||
request.headers.set("User-Agent", this._userAgent);
|
||||
return this._nextPolicy.send(request);
|
||||
};
|
||||
return UserAgentPolicy;
|
||||
}(requestPolicy_1.BaseRequestPolicy));
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"userAgentPolicy.js","sourceRoot":"","sources":["../../../lib/policies/userAgentPolicy.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,gEAA+D;AAG/D,kDAAoE;AAIpE;;;GAGG;AACH,yBAAgC,SAAiB;IAC7C,MAAM,CAAC,UAAC,UAAyB,EAAE,OAA6B;QAC5D,MAAM,CAAC,IAAI,eAAe,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/D,CAAC,CAAC;AACN,CAAC;AAJD,0CAIC;AAED;IAA8B,mCAAiB;IAC3C,yBAA6B,SAAiB,EAAE,U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,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,2CAAoB,CAAC,IAAI,EAAE,oCAA+B,IAAI,CAAC,UAAU,QAAI,CAAC,CAAC;QAC5F,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IACL,sBAAC;AAAD,CAAC,AAZD,CAA8B,iCAAiB,GAY9C"}
|
|
@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||
* A base class implementation of RequestPolicy.
|
||||
*/
|
||||
var BaseRequestPolicy = /** @class */ (function () {
|
||||
function BaseRequestPolicy(nextPolicy, options) {
|
||||
this.nextPolicy = nextPolicy;
|
||||
this.options = options;
|
||||
function BaseRequestPolicy(_nextPolicy, _options) {
|
||||
this._nextPolicy = _nextPolicy;
|
||||
this._options = _options;
|
||||
}
|
||||
/**
|
||||
* Get whether or not a log with the provided log level should be logged.
|
||||
|
@ -16,7 +16,7 @@ var BaseRequestPolicy = /** @class */ (function () {
|
|||
* @returns Whether or not a log with the provided log level should be logged.
|
||||
*/
|
||||
BaseRequestPolicy.prototype.shouldLog = function (logLevel) {
|
||||
return this.options.shouldLog(logLevel);
|
||||
return this._options.shouldLog(logLevel);
|
||||
};
|
||||
/**
|
||||
* Attempt to log the provided message to the provided logger. If no logger was provided or if
|
||||
|
@ -25,7 +25,7 @@ var BaseRequestPolicy = /** @class */ (function () {
|
|||
* @param message The message of this log.
|
||||
*/
|
||||
BaseRequestPolicy.prototype.log = function (logLevel, message) {
|
||||
this.options.log(logLevel, message);
|
||||
this._options.log(logLevel, message);
|
||||
};
|
||||
return BaseRequestPolicy;
|
||||
}());
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"requestPolicy.js","sourceRoot":"","sources":["../../lib/requestPolicy.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAoB/F;;GAEG;AACH;IACI,2BAA+B,UAAyB,EAAmB,OAA6B;QAAzE,eAAU,GAAV,UAAU,CAAe;QAAmB,YAAO,GAAP,OAAO,CAAsB;IACxG,CAAC;IAID;;;;OAIG;IACO,qCAAS,GAAnB,UAAoB,QAA8B;QAC9C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACO,+BAAG,GAAb,UAAc,QAA8B,EAAE,OAAe;QACzD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IACL,wBAAC;AAAD,CAAC,AAxBD,IAwBC;AAxBqB,8CAAiB"}
|
||||
{"version":3,"file":"requestPolicy.js","sourceRoot":"","sources":["../../lib/requestPolicy.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAoB/F;;GAEG;AACH;IACI,2BAA+B,WAA0B,EAAmB,QAA8B;QAA3E,gBAAW,GAAX,WAAW,CAAe;QAAmB,aAAQ,GAAR,QAAQ,CAAsB;IAC1G,CAAC;IAID;;;;OAIG;IACO,qCAAS,GAAnB,UAAoB,QAA8B;QAC9C,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACO,+BAAG,GAAb,UAAc,QAA8B,EAAE,OAAe;QACzD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IACL,wBAAC;AAAD,CAAC,AAxBD,IAwBC;AAxBqB,8CAAiB"}
|
|
@ -56,7 +56,6 @@ describe("fetchHttpClient", function () {
|
|||
assert.deepStrictEqual(response.request, request);
|
||||
assert.strictEqual(response.statusCode, 200);
|
||||
assert(response.headers);
|
||||
assert.strictEqual(response.headers.get("accept-ranges"), "bytes");
|
||||
assert.strictEqual(response.headers.get("connection"), "close");
|
||||
assert.strictEqual(response.headers.get("content-encoding"), "gzip");
|
||||
assert.strictEqual(response.headers.get("content-length"), "606");
|
||||
|
@ -71,5 +70,46 @@ describe("fetchHttpClient", function () {
|
|||
}
|
||||
});
|
||||
}); });
|
||||
it("should throw for awaited 404", function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var request, httpClient, error_1;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
request = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.notanexample.coms", {});
|
||||
httpClient = new fetchHttpClient_1.FetchHttpClient();
|
||||
_a.label = 1;
|
||||
case 1:
|
||||
_a.trys.push([1, 3, , 4]);
|
||||
return [4 /*yield*/, httpClient.send(request)];
|
||||
case 2:
|
||||
_a.sent();
|
||||
assert.fail("Expected error to be thrown.");
|
||||
return [3 /*break*/, 4];
|
||||
case 3:
|
||||
error_1 = _a.sent();
|
||||
assert.strictEqual(error_1.name, "FetchError");
|
||||
assert.strictEqual(error_1.code, "ENOTFOUND");
|
||||
assert.strictEqual(error_1.message, "request to http://www.notanexample.coms failed, reason: getaddrinfo ENOTFOUND www.notanexample.coms www.notanexample.coms:80");
|
||||
return [3 /*break*/, 4];
|
||||
case 4: return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
it("should reject for promised 404", function () { return __awaiter(_this, void 0, void 0, function () {
|
||||
var request, httpClient;
|
||||
return __generator(this, function (_a) {
|
||||
request = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.notanexample.coms", {});
|
||||
httpClient = new fetchHttpClient_1.FetchHttpClient();
|
||||
return [2 /*return*/, httpClient.send(request)
|
||||
.then(function () {
|
||||
assert.fail("Expected error to be thrown.");
|
||||
})
|
||||
.catch(function (error) {
|
||||
assert.strictEqual(error.name, "FetchError");
|
||||
assert.strictEqual(error.code, "ENOTFOUND");
|
||||
assert.strictEqual(error.message, "request to http://www.notanexample.coms failed, reason: getaddrinfo ENOTFOUND www.notanexample.coms www.notanexample.coms:80");
|
||||
})];
|
||||
});
|
||||
}); });
|
||||
});
|
||||
//# sourceMappingURL=fetchHttpClientTests.js.map
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"fetchHttpClientTests.js","sourceRoot":"","sources":["../../test/fetchHttpClientTests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iBA4EG;;AA9EH,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,0DAAyD;AACzD,gDAA+C;AAC/C,kDAAiD;AAGjD,QAAQ,CAAC,iBAAiB,EAAE;IACxB,EAAE,CAAC,2BAA2B,EAAE;;;;;oBACtB,OAAO,GAAG,IAAI,yBAAW,CAAC,uBAAU,CAAC,GAAG,EAAE,wBAAwB,EAAE,EAAE,CAAC,CAAC;oBACxE,UAAU,GAAG,IAAI,iCAAe,EAAE,CAAC;oBAEV,qBAAM,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;oBAAvD,QAAQ,GAAiB,SAA8B;oBAC7D,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;oBAClD,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBAC7C,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBACzB,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,CAAC;oBACnE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC;oBAChE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC,CAAC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AAE,WAAW,CAAC,CAAC;oBAC5C,MAAM,CAAC,WAAW,CAAC,OAAK,CAAC,OAAO,EAAE,8HAA8H,CAAC,CAAC;;;;;SAEzK,CAAC,CAAC;IAEH,EAAE,CAAC,gCAAgC,EAAE;;;YAC3B,OAAO,GAAG,IAAI,yBAAW,CAAC,uBAAU,CAAC,GAAG,EAAE,8BAA8B,EAAE,EAAE,CAAC,CAAC;YAC9E,UAAU,GAAG,IAAI,iCAAe,EAAE,CAAC;YAEzC,sBAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;qBAC1B,IAAI,CAAC;oBACF,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBAChD,CAAC,CAAC;qBACD,KAAK,CAAC,UAAC,KAAU;oBACd,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;oBAC7C,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;oBAC5C,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,OAAO,EAAE,8HAA8H,CAAC,CAAC;gBACtK,CAAC,CAAC,EAAC;;SACV,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@ -126,7 +126,7 @@ describe("HttpPipeline", function () {
|
|||
var response;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0: return [4 /*yield*/, this.nextPolicy.send(request)];
|
||||
case 0: return [4 /*yield*/, this._nextPolicy.send(request)];
|
||||
case 1:
|
||||
response = _a.sent();
|
||||
response.headers.set("My-Header", "My-Value");
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"version":3,"file":"httpPipelineTests.js","sourceRoot":"","sources":["../../test/httpPipelineTests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iBA4EG;;AA9EH,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AAEjC,gDA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;;oBAA7D,QAAQ,GAAiB,SAAoC;oBACnE,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;oBACtD,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC9D,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBAC7C,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAC,WAAW,EAAE,UAAU,EAAC,CAAC,CAAC;oBAC9B,qBAAM,QAAQ,CAAC,QAAQ,EAAE,EAAA;;oBAAlE,kBAAkB,GAAuB,SAAyB;oBACxE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAAC;;;;SACpD,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@ -5,7 +5,7 @@ import { HttpHeaders } from "./httpHeaders";
|
|||
import { HttpRequest } from "./httpRequest";
|
||||
import { HttpResponse } from "./httpResponse";
|
||||
|
||||
type FetchMethod = (url: string, options: RequestInit) => Response;
|
||||
type FetchMethod = (url: string, options: RequestInit) => Promise<Response>;
|
||||
|
||||
/**
|
||||
* The cached fetch method that will be used to send HTTP requests.
|
||||
|
@ -17,34 +17,24 @@ const fetch: FetchMethod = require("fetch-ponyfill")({ useCookie: true }).fetch;
|
|||
*/
|
||||
export class FetchHttpClient implements HttpClient {
|
||||
public async send(request: HttpRequest): Promise<HttpResponse> {
|
||||
let result: Promise<HttpResponse>;
|
||||
const fetchRequestOptions: RequestInit = {
|
||||
method: request.httpMethod,
|
||||
headers: request.headers.toJson(),
|
||||
body: request.body
|
||||
};
|
||||
|
||||
try {
|
||||
const fetchRequestOptions: RequestInit = {
|
||||
method: request.httpMethod,
|
||||
headers: request.headers.toJson(),
|
||||
body: request.body
|
||||
};
|
||||
const fetchResponse: Response = await fetch(request.url, fetchRequestOptions);
|
||||
|
||||
const fetchResponse: Response = await fetch(request.url, fetchRequestOptions);
|
||||
const responseHeaders = new HttpHeaders();
|
||||
const fetchResponseHeaders: Headers = fetchResponse.headers;
|
||||
fetchResponseHeaders.forEach((headerValue: string, headerName: string) => { responseHeaders.set(headerName, headerValue); });
|
||||
|
||||
const responseHeaders = new HttpHeaders();
|
||||
const fetchResponseHeaders: Headers = fetchResponse.headers;
|
||||
fetchResponseHeaders.forEach((headerValue: string, headerName: string) => { responseHeaders.set(headerName, headerValue); });
|
||||
|
||||
const response: HttpResponse = {
|
||||
request: request,
|
||||
statusCode: fetchResponse.status,
|
||||
headers: responseHeaders,
|
||||
textBody: () => fetchResponse.text(),
|
||||
deserializedBody: () => fetchResponse.json()
|
||||
};
|
||||
|
||||
result = Promise.resolve(response);
|
||||
} catch (err) {
|
||||
result = Promise.reject(err);
|
||||
}
|
||||
|
||||
return result;
|
||||
return {
|
||||
request: request,
|
||||
statusCode: fetchResponse.status,
|
||||
headers: responseHeaders,
|
||||
textBody: async () => await fetchResponse.text(),
|
||||
deserializedBody: async () => await fetchResponse.json()
|
||||
};
|
||||
}
|
||||
}
|
|
@ -32,10 +32,10 @@ export type RawHttpHeaders = { [headerName: string]: string };
|
|||
* A collection of HTTP header key/value pairs.
|
||||
*/
|
||||
export class HttpHeaders {
|
||||
private readonly headersMap: { [headerKey: string]: HttpHeader };
|
||||
private readonly _headersMap: { [headerKey: string]: HttpHeader };
|
||||
|
||||
constructor(rawHeaders?: RawHttpHeaders) {
|
||||
this.headersMap = {};
|
||||
this._headersMap = {};
|
||||
if (rawHeaders) {
|
||||
for (const headerName in rawHeaders) {
|
||||
this.set(headerName, rawHeaders[headerName]);
|
||||
|
@ -50,7 +50,7 @@ export class HttpHeaders {
|
|||
* @param headerValue The value of the header to set.
|
||||
*/
|
||||
public set(headerName: string, headerValue: string | number): void {
|
||||
this.headersMap[getHeaderKey(headerName)] = { name: headerName, value: headerValue.toString() };
|
||||
this._headersMap[getHeaderKey(headerName)] = { name: headerName, value: headerValue.toString() };
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +59,7 @@ export class HttpHeaders {
|
|||
* @param headerName The name of the header.
|
||||
*/
|
||||
public get(headerName: string): string | undefined {
|
||||
const header: HttpHeader = this.headersMap[getHeaderKey(headerName)];
|
||||
const header: HttpHeader = this._headersMap[getHeaderKey(headerName)];
|
||||
return !header ? undefined : header.value;
|
||||
}
|
||||
|
||||
|
@ -68,8 +68,8 @@ export class HttpHeaders {
|
|||
*/
|
||||
public headers(): HttpHeader[] {
|
||||
const headers: HttpHeader[] = [];
|
||||
for (const headerKey in this.headersMap) {
|
||||
headers.push(this.headersMap[headerKey]);
|
||||
for (const headerKey in this._headersMap) {
|
||||
headers.push(this._headersMap[headerKey]);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
|
|
@ -23,20 +23,20 @@ function getDefaultHttpClient(): HttpClient {
|
|||
* be applied to a HTTP response when it is received.
|
||||
*/
|
||||
export class HttpPipeline {
|
||||
private readonly httpClient: HttpClient;
|
||||
private readonly requestPolicyOptions: RequestPolicyOptions;
|
||||
private readonly _httpClient: HttpClient;
|
||||
private readonly _requestPolicyOptions: RequestPolicyOptions;
|
||||
|
||||
constructor(private readonly requestPolicyFactories: RequestPolicyFactory[], private readonly options: HttpPipelineOptions) {
|
||||
if (!this.options) {
|
||||
this.options = {};
|
||||
constructor(private readonly _requestPolicyFactories: RequestPolicyFactory[], private readonly _httpPipelineOptions: HttpPipelineOptions) {
|
||||
if (!this._httpPipelineOptions) {
|
||||
this._httpPipelineOptions = {};
|
||||
}
|
||||
|
||||
if (!this.options.httpClient) {
|
||||
this.options.httpClient = getDefaultHttpClient();
|
||||
if (!this._httpPipelineOptions.httpClient) {
|
||||
this._httpPipelineOptions.httpClient = getDefaultHttpClient();
|
||||
}
|
||||
|
||||
this.httpClient = this.options.httpClient;
|
||||
this.requestPolicyOptions = new RequestPolicyOptions(this.options.pipelineLogger);
|
||||
this._httpClient = this._httpPipelineOptions.httpClient;
|
||||
this._requestPolicyOptions = new RequestPolicyOptions(this._httpPipelineOptions.pipelineLogger);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,12 +45,12 @@ export class HttpPipeline {
|
|||
* @return A Promise that resolves to the HttpResponse from the targeted server.
|
||||
*/
|
||||
public send(request: HttpRequest): Promise<HttpResponse> {
|
||||
let requestPolicyChainHead: RequestPolicy = this.httpClient;
|
||||
if (this.requestPolicyFactories) {
|
||||
const requestPolicyFactoriesLength: number = this.requestPolicyFactories.length;
|
||||
let requestPolicyChainHead: RequestPolicy = this._httpClient;
|
||||
if (this._requestPolicyFactories) {
|
||||
const requestPolicyFactoriesLength: number = this._requestPolicyFactories.length;
|
||||
for (let i = requestPolicyFactoriesLength - 1; i >= 0; --i) {
|
||||
const requestPolicyFactory: RequestPolicyFactory = this.requestPolicyFactories[i];
|
||||
requestPolicyChainHead = requestPolicyFactory(requestPolicyChainHead, this.requestPolicyOptions);
|
||||
const requestPolicyFactory: RequestPolicyFactory = this._requestPolicyFactories[i];
|
||||
requestPolicyChainHead = requestPolicyFactory(requestPolicyChainHead, this._requestPolicyOptions);
|
||||
}
|
||||
}
|
||||
return requestPolicyChainHead.send(request);
|
||||
|
|
|
@ -18,15 +18,15 @@ export function userAgentPolicy(userAgent: string): RequestPolicyFactory {
|
|||
}
|
||||
|
||||
class UserAgentPolicy extends BaseRequestPolicy {
|
||||
constructor(private readonly userAgent: string, nextPolicy: RequestPolicy, options: RequestPolicyOptions) {
|
||||
constructor(private readonly _userAgent: string, nextPolicy: RequestPolicy, options: RequestPolicyOptions) {
|
||||
super(nextPolicy, options);
|
||||
}
|
||||
|
||||
send(request: HttpRequest): Promise<HttpResponse> {
|
||||
if (this.shouldLog(HttpPipelineLogLevel.INFO)) {
|
||||
this.log(HttpPipelineLogLevel.INFO, `Set "User-Agent" header to "${this.userAgent}".`);
|
||||
this.log(HttpPipelineLogLevel.INFO, `Set "User-Agent" header to "${this._userAgent}".`);
|
||||
}
|
||||
request.headers.set("User-Agent", this.userAgent);
|
||||
return this.nextPolicy.send(request);
|
||||
request.headers.set("User-Agent", this._userAgent);
|
||||
return this._nextPolicy.send(request);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ export interface RequestPolicy {
|
|||
* A base class implementation of RequestPolicy.
|
||||
*/
|
||||
export abstract class BaseRequestPolicy implements RequestPolicy {
|
||||
constructor(protected readonly nextPolicy: RequestPolicy, private readonly options: RequestPolicyOptions) {
|
||||
constructor(protected readonly _nextPolicy: RequestPolicy, private readonly _options: RequestPolicyOptions) {
|
||||
}
|
||||
|
||||
public abstract send(request: HttpRequest): Promise<HttpResponse>;
|
||||
|
@ -34,7 +34,7 @@ export abstract class BaseRequestPolicy implements RequestPolicy {
|
|||
* @returns Whether or not a log with the provided log level should be logged.
|
||||
*/
|
||||
protected shouldLog(logLevel: HttpPipelineLogLevel): boolean {
|
||||
return this.options.shouldLog(logLevel);
|
||||
return this._options.shouldLog(logLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,6 +44,6 @@ export abstract class BaseRequestPolicy implements RequestPolicy {
|
|||
* @param message The message of this log.
|
||||
*/
|
||||
protected log(logLevel: HttpPipelineLogLevel, message: string): void {
|
||||
this.options.log(logLevel, message);
|
||||
this._options.log(logLevel, message);
|
||||
}
|
||||
}
|
|
@ -172,6 +172,12 @@
|
|||
"integrity": "sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=",
|
||||
"dev": true
|
||||
},
|
||||
"arrify": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz",
|
||||
"integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=",
|
||||
"dev": true
|
||||
},
|
||||
"asn1.js": {
|
||||
"version": "4.10.1",
|
||||
"resolved": "https://registry.npmjs.org/asn1.js/-/asn1.js-4.10.1.tgz",
|
||||
|
@ -936,7 +942,7 @@
|
|||
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
|
||||
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
|
||||
"requires": {
|
||||
"iconv-lite": "0.4.19"
|
||||
"iconv-lite": "0.4.21"
|
||||
}
|
||||
},
|
||||
"enhanced-resolve": {
|
||||
|
@ -2465,9 +2471,12 @@
|
|||
"dev": true
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.19",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
|
||||
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ=="
|
||||
"version": "0.4.21",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.21.tgz",
|
||||
"integrity": "sha512-En5V9za5mBt2oUA03WGD3TwDv0MKAruqsuxstbMUZaj9W9k/m1CV/9py3l0L5kw9Bln8fdHQmzHSYtvpvTLpKw==",
|
||||
"requires": {
|
||||
"safer-buffer": "2.1.2"
|
||||
}
|
||||
},
|
||||
"ieee754": {
|
||||
"version": "1.1.11",
|
||||
|
@ -2886,6 +2895,12 @@
|
|||
"yallist": "2.1.2"
|
||||
}
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.4.tgz",
|
||||
"integrity": "sha512-0Dab5btKVPhibSalc9QGXb559ED7G7iLjFXBaj9Wq8O3vorueR5K5jaE3hkG6ZQINyhA/JgG6Qk4qdFQjsYV6g==",
|
||||
"dev": true
|
||||
},
|
||||
"map-cache": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/map-cache/-/map-cache-0.2.2.tgz",
|
||||
|
@ -3680,6 +3695,11 @@
|
|||
"ret": "0.1.15"
|
||||
}
|
||||
},
|
||||
"safer-buffer": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
||||
},
|
||||
"sax": {
|
||||
"version": "1.2.4",
|
||||
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
|
||||
|
@ -4280,6 +4300,30 @@
|
|||
"semver": "5.5.0"
|
||||
}
|
||||
},
|
||||
"ts-node": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-5.0.1.tgz",
|
||||
"integrity": "sha512-XK7QmDcNHVmZkVtkiwNDWiERRHPyU8nBqZB1+iv2UhOG0q3RQ9HsZ2CMqISlFbxjrYFGfG2mX7bW4dAyxBVzUw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"arrify": "1.0.1",
|
||||
"chalk": "2.3.2",
|
||||
"diff": "3.2.0",
|
||||
"make-error": "1.3.4",
|
||||
"minimist": "1.2.0",
|
||||
"mkdirp": "0.5.1",
|
||||
"source-map-support": "0.5.4",
|
||||
"yn": "2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.0.tgz",
|
||||
|
@ -4828,6 +4872,12 @@
|
|||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"yn": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz",
|
||||
"integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,8 +50,8 @@
|
|||
"@types/xml2js": "^0.4.2",
|
||||
"mocha": "^3.5.3",
|
||||
"should": "5.2.0",
|
||||
"source-map-support": "^0.5.4",
|
||||
"ts-loader": "^2.3.7",
|
||||
"ts-node": "^5.0.1",
|
||||
"tslint": "^5.7.0",
|
||||
"typescript": "^2.7.2",
|
||||
"uglify-es": "^3.1.0",
|
||||
|
@ -67,10 +67,9 @@
|
|||
},
|
||||
"scripts": {
|
||||
"tsc": "tsc -p tsconfig.json",
|
||||
"test": "npm run tsc && npm -s run-script tslint && npm -s run-script unit",
|
||||
"unit": "mocha --require source-map-support/register -t 50000 ./dist/test",
|
||||
"test": "mocha -r ts-node/register -t 50000 ./test/**/*.ts",
|
||||
"uglify": "node node_modules/uglify-es/bin/uglifyjs --source-map -c -m -o msRestBundle.min.js msRestBundle.js",
|
||||
"build": "npm -s run-script tsc && webpack && npm -s run-script uglify",
|
||||
"build": "npm run tsc && npm run tslint && webpack && npm run uglify",
|
||||
"tslint": "tslint -p . -c tslint.json --exclude test/**/*.ts"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ describe("fetchHttpClient", () => {
|
|||
assert.deepStrictEqual(response.request, request);
|
||||
assert.strictEqual(response.statusCode, 200);
|
||||
assert(response.headers);
|
||||
assert.strictEqual(response.headers.get("accept-ranges"), "bytes");
|
||||
assert.strictEqual(response.headers.get("connection"), "close");
|
||||
assert.strictEqual(response.headers.get("content-encoding"), "gzip");
|
||||
assert.strictEqual(response.headers.get("content-length"), "606");
|
||||
|
@ -76,4 +75,33 @@ describe("fetchHttpClient", () => {
|
|||
`;
|
||||
assert.strictEqual(responseBody, expectedResponseBody);
|
||||
});
|
||||
|
||||
it("should throw for awaited 404", async () => {
|
||||
const request = new HttpRequest(HttpMethod.GET, "http://www.notanexample.coms", {});
|
||||
const httpClient = new FetchHttpClient();
|
||||
|
||||
try {
|
||||
await httpClient.send(request)
|
||||
assert.fail("Expected error to be thrown.");
|
||||
} catch (error) {
|
||||
assert.strictEqual(error.name, "FetchError");
|
||||
assert.strictEqual(error.code, "ENOTFOUND");
|
||||
assert.strictEqual(error.message, "request to http://www.notanexample.coms failed, reason: getaddrinfo ENOTFOUND www.notanexample.coms www.notanexample.coms:80");
|
||||
}
|
||||
});
|
||||
|
||||
it("should reject for promised 404", async () => {
|
||||
const request = new HttpRequest(HttpMethod.GET, "http://www.notanexample.coms", {});
|
||||
const httpClient = new FetchHttpClient();
|
||||
|
||||
return httpClient.send(request)
|
||||
.then(() => {
|
||||
assert.fail("Expected error to be thrown.");
|
||||
})
|
||||
.catch((error: any) => {
|
||||
assert.strictEqual(error.name, "FetchError");
|
||||
assert.strictEqual(error.code, "ENOTFOUND");
|
||||
assert.strictEqual(error.message, "request to http://www.notanexample.coms failed, reason: getaddrinfo ENOTFOUND www.notanexample.coms www.notanexample.coms:80");
|
||||
});
|
||||
});
|
||||
});
|
|
@ -57,7 +57,7 @@ describe("HttpPipeline", () => {
|
|||
|
||||
class ResponseModifyingRequestPolicy extends BaseRequestPolicy {
|
||||
public async send(request: HttpRequest): Promise<HttpResponse> {
|
||||
const response: HttpResponse = await this.nextPolicy.send(request);
|
||||
const response: HttpResponse = await this._nextPolicy.send(request);
|
||||
response.headers.set("My-Header", "My-Value");
|
||||
return response;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ export declare type RawHttpHeaders = {
|
|||
* A collection of HTTP header key/value pairs.
|
||||
*/
|
||||
export declare class HttpHeaders {
|
||||
private readonly headersMap;
|
||||
private readonly _headersMap;
|
||||
constructor(rawHeaders?: RawHttpHeaders);
|
||||
/**
|
||||
* Set a header in this collection with the provided name and value. The name is
|
||||
|
|
|
@ -7,11 +7,11 @@ import { RequestPolicyFactory } from "./requestPolicyFactory";
|
|||
* be applied to a HTTP response when it is received.
|
||||
*/
|
||||
export declare class HttpPipeline {
|
||||
private readonly requestPolicyFactories;
|
||||
private readonly options;
|
||||
private readonly httpClient;
|
||||
private readonly requestPolicyOptions;
|
||||
constructor(requestPolicyFactories: RequestPolicyFactory[], options: HttpPipelineOptions);
|
||||
private readonly _requestPolicyFactories;
|
||||
private readonly _httpPipelineOptions;
|
||||
private readonly _httpClient;
|
||||
private readonly _requestPolicyOptions;
|
||||
constructor(_requestPolicyFactories: RequestPolicyFactory[], _httpPipelineOptions: HttpPipelineOptions);
|
||||
/**
|
||||
* Send the provided HttpRequest request.
|
||||
* @param request The HTTP request to send.
|
||||
|
|
|
@ -18,9 +18,9 @@ export interface RequestPolicy {
|
|||
* A base class implementation of RequestPolicy.
|
||||
*/
|
||||
export declare abstract class BaseRequestPolicy implements RequestPolicy {
|
||||
protected readonly nextPolicy: RequestPolicy;
|
||||
private readonly options;
|
||||
constructor(nextPolicy: RequestPolicy, options: RequestPolicyOptions);
|
||||
protected readonly _nextPolicy: RequestPolicy;
|
||||
private readonly _options;
|
||||
constructor(_nextPolicy: RequestPolicy, _options: RequestPolicyOptions);
|
||||
abstract send(request: HttpRequest): Promise<HttpResponse>;
|
||||
/**
|
||||
* Get whether or not a log with the provided log level should be logged.
|
||||
|
|
|
@ -122,18 +122,18 @@ export interface UrlParameterValue {
|
|||
}
|
||||
export declare function serializeObject(toSerialize: any): any;
|
||||
export declare const MapperType: {
|
||||
Composite: "Composite";
|
||||
Enum: "Enum";
|
||||
Sequence: "Sequence";
|
||||
Dictionary: "Dictionary";
|
||||
Base64Url: "Base64Url";
|
||||
Boolean: "Boolean";
|
||||
ByteArray: "ByteArray";
|
||||
Composite: "Composite";
|
||||
Date: "Date";
|
||||
DateTime: "DateTime";
|
||||
DateTimeRfc1123: "DateTimeRfc1123";
|
||||
Dictionary: "Dictionary";
|
||||
Enum: "Enum";
|
||||
Number: "Number";
|
||||
Object: "Object";
|
||||
Sequence: "Sequence";
|
||||
String: "String";
|
||||
Stream: "Stream";
|
||||
TimeSpan: "TimeSpan";
|
||||
|
|
Загрузка…
Ссылка в новой задаче