Changes based on code review comments

This commit is contained in:
Dan Schulte 2018-04-06 15:20:35 -07:00
Родитель 5a1a53aa6c
Коммит 9bf26c4d45
82 изменённых файлов: 824 добавлений и 646 удалений

94
dist/lib/fetchHttpClient.js поставляемый
Просмотреть файл

@ -1,6 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@ -38,61 +36,53 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
};
Object.defineProperty(exports, "__esModule", { value: true });
var httpHeaders_1 = require("./httpHeaders");
/**
* Provides the fetch() method based on the environment.
* @returns {fetch} fetch - The fetch() method available in the environment to make requests
*/
function getFetch() {
return require("fetch-ponyfill")({ useCookie: true }).fetch;
}
/**
* The cached fetch method that will be used to send HTTP requests.
*/
var fetch;
var fetch = require("fetch-ponyfill")({ useCookie: true }).fetch;
/**
* A HttpClient implementation that uses fetch to send HTTP requests.
* @param request The request to send.
*/
function fetchHttpClient(request) {
return __awaiter(this, void 0, void 0, function () {
var result, fetchRequestOptions, fetchResponse_1, responseHeaders_1, fetchResponseHeaders, response, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!fetch) {
fetch = getFetch();
}
_a.label = 1;
case 1:
_a.trys.push([1, 3, , 4]);
fetchRequestOptions = {
method: request.httpMethod,
headers: request.headers.toJson(),
body: request.body
};
return [4 /*yield*/, fetch(request.url, fetchRequestOptions)];
case 2:
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,
bodyAsText: function () { return fetchResponse_1.text(); },
bodyAsJson: function () { return fetchResponse_1.json(); }
};
result = Promise.resolve(response);
return [3 /*break*/, 4];
case 3:
err_1 = _a.sent();
result = Promise.reject(err_1);
return [3 /*break*/, 4];
case 4: return [2 /*return*/, result];
}
var FetchHttpClient = /** @class */ (function () {
function FetchHttpClient() {
}
FetchHttpClient.prototype.send = function (request) {
return __awaiter(this, void 0, void 0, function () {
var result, fetchRequestOptions, fetchResponse_1, responseHeaders_1, fetchResponseHeaders, response, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
fetchRequestOptions = {
method: request.httpMethod,
headers: request.headers.toJson(),
body: request.body
};
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];
}
});
});
});
}
exports.fetchHttpClient = fetchHttpClient;
};
return FetchHttpClient;
}());
exports.FetchHttpClient = FetchHttpClient;
//# sourceMappingURL=fetchHttpClient.js.map

2
dist/lib/fetchHttpClient.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"fetchHttpClient.js","sourceRoot":"","sources":["../../lib/fetchHttpClient.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAI/F,6CAA4C;AAI5C;;;GAGG;AACH;IACI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,E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C;AAAD,CAAC,AAhCD,IAgCC;AAhCY,0CAAe"}

2
dist/lib/httpClient.js поставляемый
Просмотреть файл

@ -1,5 +1,3 @@
"use strict";
// 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 });
//# sourceMappingURL=httpClient.js.map

2
dist/lib/httpClient.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../lib/httpClient.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F"}
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../lib/httpClient.ts"],"names":[],"mappings":""}

18
dist/lib/httpClientToRequestPolicyAdapter.js поставляемый
Просмотреть файл

@ -1,18 +0,0 @@
"use strict";
// 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 });
/**
* An adapter type that adapts a HttpClient to look like a RequestPolicy.
*/
var HttpClientToRequestPolicyAdapter = /** @class */ (function () {
function HttpClientToRequestPolicyAdapter(_httpClient) {
this._httpClient = _httpClient;
}
HttpClientToRequestPolicyAdapter.prototype.send = function (request) {
return this._httpClient(request);
};
return HttpClientToRequestPolicyAdapter;
}());
exports.HttpClientToRequestPolicyAdapter = HttpClientToRequestPolicyAdapter;
//# sourceMappingURL=httpClientToRequestPolicyAdapter.js.map

Просмотреть файл

@ -1 +0,0 @@
{"version":3,"file":"httpClientToRequestPolicyAdapter.js","sourceRoot":"","sources":["../../lib/httpClientToRequestPolicyAdapter.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAO/F;;GAEG;AACH;IACI,0CAAoB,WAAuB;QAAvB,gBAAW,GAAX,WAAW,CAAY;IAC3C,CAAC;IAED,+CAAI,GAAJ,UAAK,OAAoB;QACrB,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IACL,uCAAC;AAAD,CAAC,AAPD,IAOC;AAPY,4EAAgC"}

10
dist/lib/httpHeaders.js поставляемый
Просмотреть файл

@ -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;
};

2
dist/lib/httpHeaders.js.map поставляемый
Просмотреть файл

@ -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,WAAW,GAAG,EAAE,CAAC;QACtB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;YACb,GAAG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AAC;IAED;;OAEG;IACI,kCAAY,GAAnB;QACI,IAAM,YAAY,GAAa,EAAE,CAAC;QAClC,IAAM,OAAO,GAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7C,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YACtC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC;QACD,MAAM,CAAC,YAAY,CAAC;IACxB,CAAC;IAED;;OAEG;IACI,4BAAM,GAAb;QACI,IAAM,MAAM,GAAmB,EAAE,CAAC;QAElC,IAAM,OAAO,GAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;QAC7C,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,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"}

14
dist/lib/httpMethod.js поставляемый
Просмотреть файл

@ -2,4 +2,18 @@
// 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 });
/**
* The different HttpMethods that can be associated with a HttpRequest.
*/
var HttpMethod;
(function (HttpMethod) {
HttpMethod["GET"] = "GET";
HttpMethod["PUT"] = "PUT";
HttpMethod["POST"] = "POST";
HttpMethod["DELETE"] = "DELETE";
HttpMethod["PATCH"] = "PATCH";
HttpMethod["HEAD"] = "HEAD";
HttpMethod["OPTIONS"] = "OPTIONS";
HttpMethod["TRACE"] = "TRACE";
})(HttpMethod = exports.HttpMethod || (exports.HttpMethod = {}));
//# sourceMappingURL=httpMethod.js.map

2
dist/lib/httpMethod.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpMethod.js","sourceRoot":"","sources":["../../lib/httpMethod.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F"}
{"version":3,"file":"httpMethod.js","sourceRoot":"","sources":["../../lib/httpMethod.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F;;GAEG;AACH,IAAY,UASX;AATD,WAAY,UAAU;IAClB,yBAAW,CAAA;IACX,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,2BAAa,CAAA;IACb,iCAAmB,CAAA;IACnB,6BAAe,CAAA;AACnB,CAAC,EATW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QASrB"}

33
dist/lib/httpPipeline.js поставляемый
Просмотреть файл

@ -1,14 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 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 fetchHttpClient_1 = require("./fetchHttpClient");
var httpClientToRequestPolicyAdapter_1 = require("./httpClientToRequestPolicyAdapter");
var requestPolicyOptions_1 = require("./requestPolicyOptions");
var defaultHttpClient;
function getDefaultHttpClient() {
if (!defaultHttpClient) {
defaultHttpClient = fetchHttpClient_1.fetchHttpClient;
defaultHttpClient = new fetchHttpClient_1.FetchHttpClient();
}
return defaultHttpClient;
}
@ -17,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, options) {
this.requestPolicyFactories = requestPolicyFactories;
this.options = options;
if (!this.options) {
this.options = {};
}
if (!this._options.httpClient) {
this._options.httpClient = getDefaultHttpClient();
if (!this.options.httpClient) {
this.options.httpClient = getDefaultHttpClient();
}
this._httpClient = this._options.httpClient;
this._requestPolicyOptions = new requestPolicyOptions_1.RequestPolicyOptions(this._options.pipelineLogger);
this.httpClient = this.options.httpClient;
this.requestPolicyOptions = new requestPolicyOptions_1.RequestPolicyOptions(this.options.pipelineLogger);
}
/**
* Send the provided HttpRequest request.
@ -35,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 = new httpClientToRequestPolicyAdapter_1.HttpClientToRequestPolicyAdapter(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);

2
dist/lib/httpPipeline.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpPipeline.js","sourceRoot":"","sources":["../../lib/httpPipeline.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,qDAAoD;AAEpD,uFAAsF;AAMtF,+DAA8D;AAE9D,IAAI,iBAA6B,CAAC;AAElC;IACI,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;QACrB,iBAAiB,GAAG,iCAAe,CAAC;IACxC,CAAC;IACD,MAAM,CAAC,iBAAiB,CAAC;AAC7B,CAAC;AAED;;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EAAE,EAAE,CAAC,EAAE,CAAC;gBACzD,IAAM,oBAAoB,GAAyB,IAAI,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC;gBAClF,sBAAsB,GAAG,oBAAoB,CAAC,sBAAsB,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACrG,CAAC;QACL,CAAC;QACD,MAAM,CAAC,sBAAsB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAChD,CAAC;IACL,mBAAC;AAAD,CAAC,AAjCD,IAiCC;AAjCY,oCAAY"}

26
dist/lib/httpPipelineLogLevel.js поставляемый
Просмотреть файл

@ -24,30 +24,4 @@ var HttpPipelineLogLevel;
*/
HttpPipelineLogLevel[HttpPipelineLogLevel["INFO"] = 3] = "INFO";
})(HttpPipelineLogLevel = exports.HttpPipelineLogLevel || (exports.HttpPipelineLogLevel = {}));
/**
* Convert the provided HttpPipelineLogLevel to its string representation.
* @param logLevel The HttpPipelineLogLevel to convert to a string.
* @returns The string representation of the provided HttpPipelineLogLevel.
*/
function httpPipelineLogLevelToString(logLevel) {
var result;
switch (logLevel) {
case HttpPipelineLogLevel.ERROR:
result = "ERROR";
break;
case HttpPipelineLogLevel.INFO:
result = "INFO";
break;
case HttpPipelineLogLevel.OFF:
result = "OFF";
break;
case HttpPipelineLogLevel.WARNING:
result = "WARNING";
break;
default:
throw new Error("Unrecognized HttpPipelineLogLevel: " + logLevel);
}
return result;
}
exports.httpPipelineLogLevelToString = httpPipelineLogLevelToString;
//# sourceMappingURL=httpPipelineLogLevel.js.map

2
dist/lib/httpPipelineLogLevel.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpPipelineLogLevel.js","sourceRoot":"","sources":["../../lib/httpPipelineLogLevel.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F;;GAEG;AACH,IAAY,oBAoBX;AApBD,WAAY,oBAAoB;IAC5B;;OAEG;IACH,6DAAG,CAAA;IAEH;;OAEG;IACH,iEAAK,CAAA;IAEL;;OAEG;IACH,qEAAO,CAAA;IAEP;;OAEG;IACH,+DAAI,CAAA;AACR,CAAC,EApBW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAoB/B;AAED;;;;GAIG;AACH,sCAA6C,QAA8B;IACvE,IAAI,MAAc,CAAC;IACnB,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QACf,KAAK,oBAAoB,CAAC,KAAK;YAC3B,MAAM,GAAG,OAAO,CAAC;YACjB,KAAK,CAAC;QAEV,KAAK,oBAAoB,CAAC,IAAI;YAC1B,MAAM,GAAG,MAAM,CAAC;YAChB,KAAK,CAAC;QAEV,KAAK,oBAAoB,CAAC,GAAG;YACzB,MAAM,GAAG,KAAK,CAAC;YACf,KAAK,CAAC;QAEV,KAAK,oBAAoB,CAAC,OAAO;YAC7B,MAAM,GAAG,SAAS,CAAC;YACnB,KAAK,CAAC;QAEV;YACI,MAAM,IAAI,KAAK,CAAC,wCAAsC,QAAU,CAAC,CAAC;IAC1E,CAAC;IACD,MAAM,CAAC,MAAM,CAAC;AAClB,CAAC;AAvBD,oEAuBC"}
{"version":3,"file":"httpPipelineLogLevel.js","sourceRoot":"","sources":["../../lib/httpPipelineLogLevel.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F;;GAEG;AACH,IAAY,oBAoBX;AApBD,WAAY,oBAAoB;IAC5B;;OAEG;IACH,6DAAG,CAAA;IAEH;;OAEG;IACH,iEAAK,CAAA;IAEL;;OAEG;IACH,qEAAO,CAAA;IAEP;;OAEG;IACH,+DAAI,CAAA;AACR,CAAC,EApBW,oBAAoB,GAApB,4BAAoB,KAApB,4BAAoB,QAoB/B"}

30
dist/lib/httpPipelineLogger.js поставляемый
Просмотреть файл

@ -2,32 +2,17 @@
// 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.
*/
var ConsoleHttpPipelineLogger = /** @class */ (function () {
function ConsoleHttpPipelineLogger(_minimumLogLevel) {
this._minimumLogLevel = _minimumLogLevel;
/**
* Create a new ConsoleHttpPipelineLogger.
* @param minimumLogLevel The log level threshold for what logs will be logged.
*/
function ConsoleHttpPipelineLogger(minimumLogLevel) {
this.minimumLogLevel = minimumLogLevel;
}
Object.defineProperty(ConsoleHttpPipelineLogger.prototype, "minimumLogLevel", {
/**
* The log level threshold for what logs will be logged.
* @return The log level threshold for what logs will be logged.
*/
get: function () {
return this._minimumLogLevel;
},
/**
* Set the log level threshold for what logs will be logged.
* @param The new minimum log level.
*/
set: function (minimumLogLevel) {
this._minimumLogLevel = minimumLogLevel;
},
enumerable: true,
configurable: true
});
/**
* Log the provided message.
* @param logLevel The HttpLogDetailLevel associated with this message.
@ -36,8 +21,7 @@ var ConsoleHttpPipelineLogger = /** @class */ (function () {
* provided message.
*/
ConsoleHttpPipelineLogger.prototype.log = function (logLevel, message) {
var logLevelString = httpPipelineLogLevel_1.httpPipelineLogLevelToString(logLevel);
console.log(logLevelString + ": " + message);
console.log(logLevel + ": " + message);
};
return ConsoleHttpPipelineLogger;
}());

2
dist/lib/httpPipelineLogger.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpPipelineLogger.js","sourceRoot":"","sources":["../../lib/httpPipelineLogger.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,+DAA4F;AAuB5F;;GAEG;AACH;IACI,mCAAoB,gBAAsC;QAAtC,qBAAgB,GAAhB,gBAAgB,CAAsB;IAC1D,CAAC;IAMD,sBAAW,sDAAe;QAJ1B;;;WAGG;aACH;YACI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;QACjC,CAAC;QAED;;;WAGG;aACH,UAA2B,eAAqC;YAC5D,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAC5C,CAAC;;;OARA;IAUD;;;;;;OAMG;IACH,uCAAG,GAAH,UAAI,QAA8B,EAAE,OAAe;QAC/C,IAAM,cAAc,GAAW,mDAA4B,CAAC,QAAQ,CAAC,CAAC;QACtE,OAAO,CAAC,GAAG,CAAI,cAAc,UAAK,OAAS,CAAC,CAAC;IACjD,CAAC;IACL,gCAAC;AAAD,CAAC,AA/BD,IA+BC;AA/BY,8DAAyB"}
{"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"}

8
dist/lib/httpRequest.js поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 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 httpHeaders_1 = require("./httpHeaders");
/**
* An individual HTTP request that can be sent with a HttpClient.
@ -57,6 +57,12 @@ var HttpRequest = /** @class */ (function () {
enumerable: true,
configurable: true
});
/**
* Create a deep clone/copy of this HttpRequest.
*/
HttpRequest.prototype.clone = function () {
return JSON.parse(JSON.stringify(this));
};
return HttpRequest;
}());
exports.HttpRequest = HttpRequest;

2
dist/lib/httpRequest.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpRequest.js","sourceRoot":"","sources":["../../lib/httpRequest.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;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AC,AA9CD,IA8CC;AA9CY,kCAAW"}

43
dist/lib/policies/userAgentPolicy.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,43 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var httpPipelineLogLevel_1 = require("../httpPipelineLogLevel");
var requestPolicy_1 = require("../requestPolicy");
/**
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
*/
function userAgentPolicy(userAgent) {
return function (nextPolicy, options) {
return new UserAgentPolicy(userAgent, nextPolicy, options);
};
}
exports.userAgentPolicy = userAgentPolicy;
var UserAgentPolicy = /** @class */ (function (_super) {
__extends(UserAgentPolicy, _super);
function UserAgentPolicy(userAgent, nextPolicy, options) {
var _this = _super.call(this, nextPolicy, options) || this;
_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 + "\".");
}
request.headers.set("User-Agent", this.userAgent);
return this.nextPolicy.send(request);
};
return UserAgentPolicy;
}(requestPolicy_1.BaseRequestPolicy));
//# sourceMappingURL=userAgentPolicy.js.map

1
dist/lib/policies/userAgentPolicy.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +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,UAAyB,EAAE,OAA6B;QAAxG,YACI,kBAAM,UAAU,EAAE,OAAO,CAAC,SAC7B;QAF4B,eAAS,GAAT,SAAS,CAAQ;;IAE9C,CAAC;IAED,8BAAI,GAAJ,UAAK,OAAoB;QACrB,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,2CAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,2CAAoB,CAAC,IAAI,EAAE,oCAA+B,IAAI,CAAC,SAAS,QAAI,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IACL,sBAAC;AAAD,CAAC,AAZD,CAA8B,iCAAiB,GAY9C"}

43
dist/lib/policies/userAgentPolicyFactory.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,43 @@
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var httpPipelineLogLevel_1 = require("../httpPipelineLogLevel");
var requestPolicy_1 = require("../requestPolicy");
/**
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
*/
function userAgentPolicyFactory(userAgent) {
return function (nextPolicy, options) {
return new UserAgentPolicy(userAgent, nextPolicy, options);
};
}
exports.userAgentPolicyFactory = userAgentPolicyFactory;
var UserAgentPolicy = /** @class */ (function (_super) {
__extends(UserAgentPolicy, _super);
function UserAgentPolicy(userAgent, nextPolicy, options) {
var _this = _super.call(this, nextPolicy, options) || this;
_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 + "\".");
}
request.headers.set("User-Agent", this.userAgent);
return this.nextPolicy.send(request);
};
return UserAgentPolicy;
}(requestPolicy_1.BaseRequestPolicy));
//# sourceMappingURL=userAgentPolicyFactory.js.map

1
dist/lib/policies/userAgentPolicyFactory.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"userAgentPolicyFactory.js","sourceRoot":"","sources":["../../../lib/policies/userAgentPolicyFactory.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,gEAA+D;AAG/D,kDAAoE;AAIpE;;;GAGG;AACH,gCAAuC,SAAiB;IACpD,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,wDAIC;AAED;IAA8B,mCAAiB;IAC3C,yBAA6B,SAAiB,EAAE,UAAyB,EAAE,OAA6B;QAAxG,YACI,kBAAM,UAAU,EAAE,OAAO,CAAC,SAC7B;QAF4B,eAAS,GAAT,SAAS,CAAQ;;IAE9C,CAAC;IAED,8BAAI,GAAJ,UAAK,OAAoB;QACrB,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,2CAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,2CAAoB,CAAC,IAAI,EAAE,oCAA+B,IAAI,CAAC,SAAS,QAAI,CAAC,CAAC;QAC3F,CAAC;QACD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IACL,sBAAC;AAAD,CAAC,AAZD,CAA8B,iCAAiB,GAY9C"}

Просмотреть файл

@ -1,6 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -12,8 +10,10 @@ var __extends = (this && this.__extends) || (function () {
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var requestPolicy_1 = require("../requestPolicy");
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var httpPipelineLogLevel_1 = require("../httpPipelineLogLevel");
var requestPolicy_1 = require("../requestPolicy");
/**
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
@ -26,16 +26,16 @@ function userAgentRequestPolicyFactory(userAgent) {
exports.userAgentRequestPolicyFactory = userAgentRequestPolicyFactory;
var UserAgentRequestPolicy = /** @class */ (function (_super) {
__extends(UserAgentRequestPolicy, _super);
function UserAgentRequestPolicy(_userAgent, nextPolicy, options) {
function UserAgentRequestPolicy(userAgent, nextPolicy, options) {
var _this = _super.call(this, nextPolicy, options) || this;
_this._userAgent = _userAgent;
_this.userAgent = userAgent;
return _this;
}
UserAgentRequestPolicy.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);
request.headers.set("User-Agent", this.userAgent);
return this.nextPolicy.send(request);
};
return UserAgentRequestPolicy;

Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"userAgentRequestPolicyFactory.js","sourceRoot":"","sources":["../../../lib/policies/userAgentRequestPolicyFactory.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;;;;;;;;;;;AAE/F,kDAAoE;AAKpE,gEAA+D;AAE/D;;;GAGG;AACH,uCAA8C,SAAiB;IAC3D,MAAM,CAAC,UAAC,UAAyB,EAAE,OAA6B;QAC5D,MAAM,CAAC,IAAI,sBAAsB,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IACtE,CAAC,CAAC;AACN,CAAC;AAJD,sEAIC;AAED;IAAqC,0CAAiB;IAClD,gCAAoB,UAAkB,EAAE,UAAyB,EAAE,OAA6B;QAAhG,YACI,kBAAM,UAAU,EAAE,OAAO,CAAC,SAC7B;QAFmB,gBAAU,GAAV,UAAU,CAAQ;;IAEtC,CAAC;IAED,qCAAI,GAAJ,UAAK,OAAoB;QACrB,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,2CAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,GAAG,CAAC,2CAAoB,CAAC,IAAI,EAAE,o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,6BAAC;AAAD,CAAC,AAZD,CAAqC,iCAAiB,GAYrD"}

20
dist/lib/requestPolicy.js поставляемый
Просмотреть файл

@ -6,27 +6,17 @@ 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;
}
Object.defineProperty(BaseRequestPolicy.prototype, "nextPolicy", {
/**
* The next RequestPolicy in the HttpPipeline.
*/
get: function () {
return this._nextPolicy;
},
enumerable: true,
configurable: true
});
/**
* Get whether or not a log with the provided log level should be logged.
* @param logLevel The log level of the log that will be logged.
* @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
@ -35,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;
}());

2
dist/lib/requestPolicy.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"requestPolicy.js","sourceRoot":"","sources":["../../lib/requestPolicy.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAoB/F;;GAEG;AACH;IACI,2BAAoB,WAA0B,EAAU,QAA8B;QAAlE,gBAAW,GAAX,WAAW,CAAe;QAAU,aAAQ,GAAR,QAAQ,CAAsB;IACtF,CAAC;IAOD,sBAAc,yCAAU;QAHxB;;WAEG;aACH;YACI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;QAC5B,CAAC;;;OAAA;IAED;;;;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,AA/BD,IA+BC;AA/BqB,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,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"}

2
dist/lib/requestPolicyFactory.js поставляемый
Просмотреть файл

@ -1,5 +1,3 @@
"use strict";
// 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 });
//# sourceMappingURL=requestPolicyFactory.js.map

2
dist/lib/requestPolicyFactory.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"requestPolicyFactory.js","sourceRoot":"","sources":["../../lib/requestPolicyFactory.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F"}
{"version":3,"file":"requestPolicyFactory.js","sourceRoot":"","sources":["../../lib/requestPolicyFactory.ts"],"names":[],"mappings":""}

23
dist/test/fakeHttpClient.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A function that can send HttpRequests and receive promised HttpResponses.
* @param request The HTTP request to send.
* @returns A Promise that resolves to the HttpResponse from the targeted server.
*/
var FakeHttpClient = /** @class */ (function () {
function FakeHttpClient(sendFunction) {
this.sendFunction = sendFunction;
}
/**
* Send the provided HttpRequest and return a Promise that resolves to the HttpResponse from the
* targeted server.
* @param request The HttpRequest to send.
*/
FakeHttpClient.prototype.send = function (request) {
return this.sendFunction(request);
};
return FakeHttpClient;
}());
exports.FakeHttpClient = FakeHttpClient;
//# sourceMappingURL=fakeHttpClient.js.map

1
dist/test/fakeHttpClient.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"fakeHttpClient.js","sourceRoot":"","sources":["../../test/fakeHttpClient.ts"],"names":[],"mappings":";;AAMA;;;;GAIG;AACH;IACI,wBAA6B,YAA6D;QAA7D,iBAAY,GAAZ,YAAY,CAAiD;IAC1F,CAAC;IAED;;;;OAIG;IACI,6BAAI,GAAX,UAAY,OAAoB;QAC5B,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACtC,CAAC;IACL,qBAAC;AAAD,CAAC,AAZD,IAYC;AAZY,wCAAc"}

90
dist/test/fetchHttpClientTests.js поставляемый
Просмотреть файл

@ -1,31 +1,75 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
// 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 fetchHttpClient_1 = require("../lib/fetchHttpClient");
var httpRequest_1 = require("../lib/httpRequest");
var assert = require("assert");
var fetchHttpClient_1 = require("../lib/fetchHttpClient");
var httpMethod_1 = require("../lib/httpMethod");
var httpRequest_1 = require("../lib/httpRequest");
describe("fetchHttpClient", function () {
it("should send HTTP requests", function () {
var request = new httpRequest_1.HttpRequest("GET", "http://www.example.com", {});
return fetchHttpClient_1.fetchHttpClient(request)
.then(function (response) {
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");
assert.strictEqual(response.headers.get("content-type"), "text/html");
assert.strictEqual(response.headers.get("vary"), "Accept-Encoding");
return response.bodyAsText();
})
.then(function (responseBody) {
assert(responseBody);
var expectedResponseBody = "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n border-radius: 1em;\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n body {\n background-color: #fff;\n }\n div {\n width: auto;\n margin: 0 auto;\n border-radius: 0;\n padding: 1em;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n";
assert.strictEqual(responseBody, expectedResponseBody);
it("should send HTTP requests", function () { return __awaiter(_this, void 0, void 0, function () {
var request, httpClient, response, responseBody, expectedResponseBody;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
request = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.example.com", {});
httpClient = new fetchHttpClient_1.FetchHttpClient();
return [4 /*yield*/, httpClient.send(request)];
case 1:
response = _a.sent();
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");
assert.strictEqual(response.headers.get("content-type"), "text/html");
assert.strictEqual(response.headers.get("vary"), "Accept-Encoding");
return [4 /*yield*/, response.textBody()];
case 2:
responseBody = _a.sent();
expectedResponseBody = "<!doctype html>\n<html>\n<head>\n <title>Example Domain</title>\n\n <meta charset=\"utf-8\" />\n <meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style type=\"text/css\">\n body {\n background-color: #f0f0f2;\n margin: 0;\n padding: 0;\n font-family: \"Open Sans\", \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n \n }\n div {\n width: 600px;\n margin: 5em auto;\n padding: 50px;\n background-color: #fff;\n border-radius: 1em;\n }\n a:link, a:visited {\n color: #38488f;\n text-decoration: none;\n }\n @media (max-width: 700px) {\n body {\n background-color: #fff;\n }\n div {\n width: auto;\n margin: 0 auto;\n border-radius: 0;\n padding: 1em;\n }\n }\n </style> \n</head>\n\n<body>\n<div>\n <h1>Example Domain</h1>\n <p>This domain is established to be used for illustrative examples in documents. You may use this\n domain in examples without prior coordination or asking for permission.</p>\n <p><a href=\"http://www.iana.org/domains/example\">More information...</a></p>\n</div>\n</body>\n</html>\n";
assert.strictEqual(responseBody, expectedResponseBody);
return [2 /*return*/];
}
});
});
}); });
});
//# sourceMappingURL=fetchHttpClientTests.js.map

2
dist/test/fetchHttpClientTests.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"fetchHttpClientTests.js","sourceRoot":"","sources":["../../test/fetchHttpClientTests.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,0DAAyD;AACzD,kDAAiD;A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QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,CAAC;oBAClE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,EAAE,WAAW,CAAC,CAAC;oBACtE,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC;oBAC3B,qBAAM,QAAQ,CAAC,QAAQ,EAAE,EAAA;;oBAA5D,YAAY,GAAuB,SAAyB;oBAC5D,oBAAoB,GAClC,4zCAkDC,CAAC;oBACM,MAAM,CAAC,WAAW,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;;;;SAC1D,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

21
dist/test/httpPipelineLogLevelTests.js поставляемый
Просмотреть файл

@ -1,21 +0,0 @@
"use strict";
// 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("../lib/httpPipelineLogLevel");
var assert = require("assert");
describe("httpPipelineLogLevelToString()", function () {
it("should work with ERROR", function () {
assert.strictEqual(httpPipelineLogLevel_1.httpPipelineLogLevelToString(httpPipelineLogLevel_1.HttpPipelineLogLevel.ERROR), "ERROR");
});
it("should work with INFO", function () {
assert.strictEqual(httpPipelineLogLevel_1.httpPipelineLogLevelToString(httpPipelineLogLevel_1.HttpPipelineLogLevel.INFO), "INFO");
});
it("should work with WARNING", function () {
assert.strictEqual(httpPipelineLogLevel_1.httpPipelineLogLevelToString(httpPipelineLogLevel_1.HttpPipelineLogLevel.WARNING), "WARNING");
});
it("should work with OFF", function () {
assert.strictEqual(httpPipelineLogLevel_1.httpPipelineLogLevelToString(httpPipelineLogLevel_1.HttpPipelineLogLevel.OFF), "OFF");
});
});
//# sourceMappingURL=httpPipelineLogLevelTests.js.map

1
dist/test/httpPipelineLogLevelTests.js.map поставляемый
Просмотреть файл

@ -1 +0,0 @@
{"version":3,"file":"httpPipelineLogLevelTests.js","sourceRoot":"","sources":["../../test/httpPipelineLogLevelTests.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,oEAAiG;AACjG,+BAAiC;AAEjC,QAAQ,CAAC,gCAAgC,EAAE;IACvC,EAAE,CAAC,wBAAwB,EAAE;QACzB,MAAM,CAAC,WAAW,CAAC,mDAA4B,CAAC,2CAAoB,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC;IAC1F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uBAAuB,EAAE;QACxB,MAAM,CAAC,WAAW,CAAC,mDAA4B,CAAC,2CAAoB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;IACxF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0BAA0B,EAAE;QAC3B,MAAM,CAAC,WAAW,CAAC,mDAA4B,CAAC,2CAAoB,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;IAC9F,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sBAAsB,EAAE;QACvB,MAAM,CAAC,WAAW,CAAC,mDAA4B,CAAC,2CAAoB,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IACtF,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

209
dist/test/httpPipelineTests.js поставляемый
Просмотреть файл

@ -1,6 +1,4 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
@ -11,81 +9,150 @@ var __extends = (this && this.__extends) || (function () {
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var requestPolicy_1 = require("../lib/requestPolicy");
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var httpMethod_1 = require("../lib/httpMethod");
var httpPipeline_1 = require("../lib/httpPipeline");
var httpRequest_1 = require("../lib/httpRequest");
var userAgentPolicy_1 = require("../lib/policies/userAgentPolicy");
var requestPolicy_1 = require("../lib/requestPolicy");
var fakeHttpClient_1 = require("./fakeHttpClient");
var inMemoryHttpResponse_1 = require("./inMemoryHttpResponse");
var userAgentRequestPolicyFactory_1 = require("../lib/policies/userAgentRequestPolicyFactory");
var assert = require("assert");
describe("HttpPipeline", function () {
it("should send requests when no request policies are assigned", function () {
var httpClient = function (request) {
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello"));
};
var httpPipeline = new httpPipeline_1.HttpPipeline([], { httpClient: httpClient });
var httpRequest = new httpRequest_1.HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then(function (response) {
assert.deepStrictEqual(response.request, httpRequest);
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return response.bodyAsText();
})
.then(function (responseBodyAsText) {
assert.strictEqual("hello", responseBodyAsText);
});
});
it("should send requests when request-modifying request policies are assigned", function () {
var httpClient = function (request) {
assert.deepStrictEqual(request.headers.toJson(), { "User-Agent": "my user agent string" });
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello2"));
};
var httpPipeline = new httpPipeline_1.HttpPipeline([userAgentRequestPolicyFactory_1.userAgentRequestPolicyFactory("my user agent string")], { httpClient: httpClient });
var httpRequest = new httpRequest_1.HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then(function (response) {
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), { "User-Agent": "my user agent string" });
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return response.bodyAsText();
})
.then(function (responseBodyAsText) {
assert.strictEqual("hello2", responseBodyAsText);
});
});
it("should send requests when response-modifying request policies are assigned", function () {
var httpClient = function (request) {
assert.deepStrictEqual(request.headers.toJson(), {});
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello3"));
};
var ResponseModifyingRequestPolicy = /** @class */ (function (_super) {
__extends(ResponseModifyingRequestPolicy, _super);
function ResponseModifyingRequestPolicy() {
return _super !== null && _super.apply(this, arguments) || this;
it("should send requests when no request policies are assigned", function () { return __awaiter(_this, void 0, void 0, function () {
var httpClient, httpPipeline, httpRequest, response, responseBodyAsText;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
httpClient = new fakeHttpClient_1.FakeHttpClient(function (request) {
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello"));
});
httpPipeline = new httpPipeline_1.HttpPipeline([], { httpClient: httpClient });
httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.example.com", {});
return [4 /*yield*/, httpPipeline.send(httpRequest)];
case 1:
response = _a.sent();
assert.deepStrictEqual(response.request, httpRequest);
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return [4 /*yield*/, response.textBody()];
case 2:
responseBodyAsText = _a.sent();
assert.strictEqual("hello", responseBodyAsText);
return [2 /*return*/];
}
ResponseModifyingRequestPolicy.prototype.send = function (request) {
return this.nextPolicy.send(request).then(function (response) {
response.headers.set("My-Header", "My-Value");
return response;
});
};
return ResponseModifyingRequestPolicy;
}(requestPolicy_1.BaseRequestPolicy));
var httpPipeline = new httpPipeline_1.HttpPipeline([function (nextPolicy, options) { return new ResponseModifyingRequestPolicy(nextPolicy, options); }], { httpClient: httpClient });
var httpRequest = new httpRequest_1.HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then(function (response) {
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), {});
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), { "My-Header": "My-Value" });
return response.bodyAsText();
})
.then(function (responseBodyAsText) {
assert.strictEqual("hello3", responseBodyAsText);
});
});
}); });
it("should send requests when request-modifying request policies are assigned", function () { return __awaiter(_this, void 0, void 0, function () {
var httpClient, httpPipeline, httpRequest, response, responseBodyAsText;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
httpClient = new fakeHttpClient_1.FakeHttpClient(function (request) {
assert.deepStrictEqual(request.headers.toJson(), { "User-Agent": "my user agent string" });
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello2"));
});
httpPipeline = new httpPipeline_1.HttpPipeline([userAgentPolicy_1.userAgentPolicy("my user agent string")], { httpClient: httpClient });
httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.example.com", {});
return [4 /*yield*/, httpPipeline.send(httpRequest)];
case 1:
response = _a.sent();
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), { "User-Agent": "my user agent string" });
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return [4 /*yield*/, response.textBody()];
case 2:
responseBodyAsText = _a.sent();
assert.strictEqual("hello2", responseBodyAsText);
return [2 /*return*/];
}
});
}); });
it("should send requests when response-modifying request policies are assigned", function () { return __awaiter(_this, void 0, void 0, function () {
var httpClient, ResponseModifyingRequestPolicy, httpPipeline, httpRequest, response, responseBodyAsText;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
httpClient = new fakeHttpClient_1.FakeHttpClient(function (request) {
assert.deepStrictEqual(request.headers.toJson(), {});
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}, "hello3"));
});
ResponseModifyingRequestPolicy = /** @class */ (function (_super) {
__extends(ResponseModifyingRequestPolicy, _super);
function ResponseModifyingRequestPolicy() {
return _super !== null && _super.apply(this, arguments) || this;
}
ResponseModifyingRequestPolicy.prototype.send = function (request) {
return __awaiter(this, void 0, void 0, function () {
var response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.nextPolicy.send(request)];
case 1:
response = _a.sent();
response.headers.set("My-Header", "My-Value");
return [2 /*return*/, response];
}
});
});
};
return ResponseModifyingRequestPolicy;
}(requestPolicy_1.BaseRequestPolicy));
httpPipeline = new httpPipeline_1.HttpPipeline([function (nextPolicy, options) { return new ResponseModifyingRequestPolicy(nextPolicy, options); }], { httpClient: httpClient });
httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "http://www.example.com", {});
return [4 /*yield*/, httpPipeline.send(httpRequest)];
case 1:
response = _a.sent();
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), {});
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), { "My-Header": "My-Value" });
return [4 /*yield*/, response.textBody()];
case 2:
responseBodyAsText = _a.sent();
assert.strictEqual("hello3", responseBodyAsText);
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=httpPipelineTests.js.map

2
dist/test/httpPipelineTests.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpPipelineTests.js","sourceRoot":"","sources":["../../test/httpPipelineTests.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;;;;;;;;;;;AAE/F,sDAAyD;AAEzD,oDAAmD;AACnD,kDAAiD;AAEjD,+DAA8D;AAC9D,+FAA8F;AAC9F,+BAAiC;AAEjC,QAAQ,CAAC,cAAc,EAAE;IACrB,EAAE,CAAC,4DAA4D,EAAE;QAC7D,IAAM,UAAU,GAAe,UAAC,OAAoB;YAChD,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,2CAAoB,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;QAChF,CAAC,CAAC;QAEF,IAAM,YAAY,GAAG,IAAI,2BAAY,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC,CAAC;Q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C9B,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"}

23
dist/test/httpRequestTests.js поставляемый
Просмотреть файл

@ -1,14 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 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 httpRequest_1 = require("../lib/httpRequest");
var assert = require("assert");
var httpMethod_1 = require("../lib/httpMethod");
var httpRequest_1 = require("../lib/httpRequest");
describe("HttpRequest", function () {
describe("constructor", function () {
it("should throw an Error when the url is \"\"", function () {
try {
new httpRequest_1.HttpRequest("GET", "", {});
new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "", {});
assert.fail("Should have thrown an error.");
}
catch (error) {
@ -17,29 +18,29 @@ describe("HttpRequest", function () {
}
});
it("should return a valid GET HttpRequest when the url is \"www.example.com\"", function () {
var httpRequest = new httpRequest_1.HttpRequest("GET", "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, "GET");
var httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, httpMethod_1.HttpMethod.GET);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, undefined);
});
it("should return a valid POST HttpRequest when the body is undefined", function () {
var httpRequest = new httpRequest_1.HttpRequest("POST", "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, "POST");
var httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.POST, "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, httpMethod_1.HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, undefined);
});
it("should return a valid POST HttpRequest when the body is \"\"", function () {
var httpRequest = new httpRequest_1.HttpRequest("POST", "www.example.com", {}, "");
assert.strictEqual(httpRequest.httpMethod, "POST");
var httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.POST, "www.example.com", {}, "");
assert.strictEqual(httpRequest.httpMethod, httpMethod_1.HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, "");
});
it("should return a valid POST HttpRequest when the body is \"hello\"", function () {
var httpRequest = new httpRequest_1.HttpRequest("POST", "www.example.com", { "Content-Length": "5" }, "hello");
assert.strictEqual(httpRequest.httpMethod, "POST");
var httpRequest = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.POST, "www.example.com", { "Content-Length": "5" }, "hello");
assert.strictEqual(httpRequest.httpMethod, httpMethod_1.HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), { "Content-Length": "5" });
assert.strictEqual(httpRequest.body, "hello");

2
dist/test/httpRequestTests.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"httpRequestTests.js","sourceRoot":"","sources":["../../test/httpRequestTests.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAE/F,kDAAiD;AACjD,+BAAiC;AAEjC,QAAQ,CAAC,aAAa,EAAE;IACpB,QAAQ,CAAC,aAAa,EAAE;QACpB,EAAE,CAAC,4CAA0C,EAAE;YAC3C,IAAI,CAAC;gBACD,IAAI,yBAAW,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC/B,MAAM,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;YAChD,CAAC;YAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;gBACb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D,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,8DAA4D,EAAE;YAC7D,IAAM,WAAW,GAAgB,IAAI,yBAAW,CAAC,uBAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAC7F,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,UAAU,EAAE,uBAAU,CAAC,IAAI,CAAC,CAAC;YAC5D,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YACvD,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;YACzD,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,mEAAiE,EAAE;YAClE,IAAM,WAAW,GAAgB,IAAI,yBAAW,CAAC,uBAAU,CAAC,IAAI,EAAE,iBAAiB,EAAE,EAAC,gBAAgB,EAAE,GAAG,EAAC,EAAE,OAAO,CAAC,CAAC;YACvH,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,UAAU,EAAE,uBAAU,CAAC,IAAI,CAAC,CAAC;YAC5D,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;YACvD,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAC,gBAAgB,EAAE,GAAG,EAAC,CAAC,CAAC;YAC9E,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

18
dist/test/inMemoryHttpClient.js поставляемый
Просмотреть файл

@ -1,18 +0,0 @@
"use strict";
// 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 });
/**
* A simple HttpClient implementation that uses a provided function to respond to HttpRequests.
*/
var InMemoryHttpClient = /** @class */ (function () {
function InMemoryHttpClient(_requestHandler) {
this._requestHandler = _requestHandler;
}
InMemoryHttpClient.prototype.send = function (request) {
return this._requestHandler(request);
};
return InMemoryHttpClient;
}());
exports.InMemoryHttpClient = InMemoryHttpClient;
//# sourceMappingURL=inMemoryHttpClient.js.map

1
dist/test/inMemoryHttpClient.js.map поставляемый
Просмотреть файл

@ -1 +0,0 @@
{"version":3,"file":"inMemoryHttpClient.js","sourceRoot":"","sources":["../../test/inMemoryHttpClient.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAM/F;;GAEG;AACH;IACI,4BAAoB,eAAgE;QAAhE,oBAAe,GAAf,eAAe,CAAiD;IACpF,CAAC;IAED,iCAAI,GAAJ,UAAK,OAAoB;QACrB,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IACL,yBAAC;AAAD,CAAC,AAPD,IAOC;AAPY,gDAAkB"}

5
dist/test/inMemoryHttpPipelineLogger.js поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 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("../lib/httpPipelineLogLevel");
/**
* An in-memory HttpPipelineLogger that can be used for testing.
@ -33,8 +33,7 @@ var InMemoryHttpPipelineLogger = /** @class */ (function () {
configurable: true
});
InMemoryHttpPipelineLogger.prototype.log = function (logLevel, message) {
var logLevelString = httpPipelineLogLevel_1.httpPipelineLogLevelToString(logLevel);
this._logs.push(logLevelString + ": " + message);
this._logs.push(httpPipelineLogLevel_1.HttpPipelineLogLevel[logLevel] + ": " + message);
};
return InMemoryHttpPipelineLogger;
}());

2
dist/test/inMemoryHttpPipelineLogger.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"inMemoryHttpPipelineLogger.js","sourceRoot":"","sources":["../../test/inMemoryHttpPipelineLogger.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAG/F,oEAAiG;AAEjG;;GAEG;AACH;IAGI,oCAAoB,gBAAkE;QAAlE,iCAAA,EAAA,mBAAyC,2CAAoB,CAAC,IAAI;QAAlE,qBAAgB,GAAhB,gBAAgB,CAAkD;QAClF,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAKD,sBAAW,4CAAI;QAHf;;WAEG;aACH;YACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC;;;OAAA;IAED,sBAAW,uDAAe;aAA1B;YACI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;QACjC,CAAC;aAED,UAA2B,eAAqC;YAC5D,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAC5C,CAAC;;;OAJA;IAMM,wCAAG,GAAV,UAAW,QAA8B,EAAE,OAAe;QACtD,IAAM,cAAc,GAAW,mDAA4B,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAI,cAAc,UAAK,OAAS,CAAC,CAAC;IACrD,CAAC;IACL,iCAAC;AAAD,CAAC,AA1BD,IA0BC;AA1BY,gEAA0B"}
{"version":3,"file":"inMemoryHttpPipelineLogger.js","sourceRoot":"","sources":["../../test/inMemoryHttpPipelineLogger.ts"],"names":[],"mappings":";;AAAA,4DAA4D;AAC5D,+FAA+F;AAC/F,oEAAmE;AAGnE;;GAEG;AACH;IAGI,oCAAoB,gBAAkE;QAAlE,iCAAA,EAAA,mBAAyC,2CAAoB,CAAC,IAAI;QAAlE,qBAAgB,GAAhB,gBAAgB,CAAkD;QAClF,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;IACpB,CAAC;IAKD,sBAAW,4CAAI;QAHf;;WAEG;aACH;YACI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QACtB,CAAC;;;OAAA;IAED,sBAAW,uDAAe;aAA1B;YACI,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC;QACjC,CAAC;aAED,UAA2B,eAAqC;YAC5D,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAC5C,CAAC;;;OAJA;IAMM,wCAAG,GAAV,UAAW,QAA8B,EAAE,OAAe;QACtD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAI,2CAAoB,CAAC,QAAQ,CAAC,UAAK,OAAS,CAAC,CAAC;IACrE,CAAC;IACL,iCAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,gEAA0B"}

6
dist/test/inMemoryHttpResponse.js поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// 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 httpHeaders_1 = require("../lib/httpHeaders");
var InMemoryHttpResponse = /** @class */ (function () {
function InMemoryHttpResponse(_request, _statusCode, headers, _bodyText) {
@ -31,10 +31,10 @@ var InMemoryHttpResponse = /** @class */ (function () {
enumerable: true,
configurable: true
});
InMemoryHttpResponse.prototype.bodyAsText = function () {
InMemoryHttpResponse.prototype.textBody = function () {
return Promise.resolve(this._bodyText);
};
InMemoryHttpResponse.prototype.bodyAsJson = function () {
InMemoryHttpResponse.prototype.deserializedBody = function () {
return Promise.resolve(this._bodyText ? JSON.parse(this._bodyText) : undefined);
};
return InMemoryHttpResponse;

2
dist/test/inMemoryHttpResponse.js.map поставляемый
Просмотреть файл

@ -1 +1 @@
{"version":3,"file":"inMemoryHttpResponse.js","sourceRoot":"","sources":["../../test/inMemoryHttpResponse.ts"],"names":[],"mappings":";AAAA,4DAA4D;AAC5D,+FAA+F;;AAI/F,kDAAiE;AAEjE;IAGI,8BAAoB,Q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GAAG,CAAC,OAAO,YAAY,yBAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,yBAAW,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,sBAAW,yCAAO;aAAlB;YACI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;;;OAAA;IAED,sBAAW,4CAAU;aAArB;YACI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC;QAC5B,CAAC;;;OAAA;IAED,sBAAW,yCAAO;aAAlB;YACI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC;QACzB,CAAC;;;OAAA;IAED,uCAAQ,GAAR;QACI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,+CAAgB,GAAhB;QACI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACpF,CAAC;IACL,2BAAC;AAAD,CAAC,AAzBD,IAyBC;AAzBY,oDAAoB"}

71
dist/test/policies/userAgentPolicyTests.js поставляемый Normal file
Просмотреть файл

@ -0,0 +1,71 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [0, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
var assert = require("assert");
var httpMethod_1 = require("../../lib/httpMethod");
var httpRequest_1 = require("../../lib/httpRequest");
var userAgentPolicy_1 = require("../../lib/policies/userAgentPolicy");
var requestPolicyOptions_1 = require("../../lib/requestPolicyOptions");
var inMemoryHttpResponse_1 = require("../inMemoryHttpResponse");
describe("userAgentPolicy", function () {
it("assigns the 'User-Agent' header to requests and does nothing to responses", function () { return __awaiter(_this, void 0, void 0, function () {
var policyFactory, nextPolicy, policy, request, response;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
policyFactory = userAgentPolicy_1.userAgentPolicy("my-user-agent-string");
nextPolicy = {
send: function (request) {
return Promise.resolve(new inMemoryHttpResponse_1.InMemoryHttpResponse(request, 200, {}));
}
};
policy = policyFactory(nextPolicy, new requestPolicyOptions_1.RequestPolicyOptions());
request = new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "https://spam.com", {});
return [4 /*yield*/, policy.send(request)];
case 1:
response = _a.sent();
assert.deepStrictEqual(request, new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "https://spam.com", { "User-Agent": "my-user-agent-string" }));
assert.deepStrictEqual(response.request, new httpRequest_1.HttpRequest(httpMethod_1.HttpMethod.GET, "https://spam.com", { "User-Agent": "my-user-agent-string" }));
return [2 /*return*/];
}
});
}); });
});
//# sourceMappingURL=userAgentPolicyTests.js.map

1
dist/test/policies/userAgentPolicyTests.js.map поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
{"version":3,"file":"userAgentPolicyTests.js","sourceRoot":"","sources":["../../../test/policies/userAgentPolicyTests.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iBA2BG;;AA7BH,4DAA4D;AAC5D,+FAA+F;AAC/F,+BAAiC;AACjC,mDAAkD;AAClD,qDAAoD;AAEpD,sEAAqE;AAGrE,uEAAsE;AACtE,gEAA+D;AAE/D,QAAQ,CAAC,iBAAiB,EAAE;IACxB,EAAE,CAAC,2EAA2E,EAAE;;;;;oBACtE,aAAa,GAAyB,iCAAe,CAAC,sBAAsB,CAAC,CAAC;oBAE9E,UAAU,GAAkB;wBAC9B,IAAI,EAAE,UAAC,OAAoB;4BACvB,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,2CAAoB,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;wBACvE,CAAC;qBACJ,CAAA;oBAEK,MAAM,GAAkB,aAAa,CAAC,UAAU,EAAE,IAAI,2CAAoB,EAAE,CAAC,CAAC;oBAC9E,OAAO,GAAG,IAAI,yBAAW,CAAC,uBAAU,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE,CAAC,CAAC;oBACzC,qBAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAA;;oBAAnD,QAAQ,GAAiB,SAA0B;oBAEzD,MAAM,CAAC,eAAe,CAAC,OAAO,EAAE,IAAI,yBAAW,CAAC,uBAAU,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAC,YAAY,EAAE,sBAAsB,EAAC,CAAC,CAAC,CAAC;oBAC7H,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,yBAAW,CAAC,uBAAU,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAC,YAAY,EAAE,sBAAsB,EAAC,CAAC,CAAC,CAAC;;;;SACzI,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}

Просмотреть файл

@ -1,60 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpClient } from "./httpClient";
import { HttpHeaders } from "./httpHeaders";
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
type FetchMethod = (url: string, options: RequestInit) => Response;
/**
* Provides the fetch() method based on the environment.
* @returns {fetch} fetch - The fetch() method available in the environment to make requests
*/
function getFetch(): FetchMethod {
return require("fetch-ponyfill")({ useCookie: true }).fetch;
}
/**
* The cached fetch method that will be used to send HTTP requests.
*/
let fetch: FetchMethod;
const fetch: FetchMethod = require("fetch-ponyfill")({ useCookie: true }).fetch;
/**
* A HttpClient implementation that uses fetch to send HTTP requests.
* @param request The request to send.
*/
export async function fetchHttpClient(request: HttpRequest): Promise<HttpResponse> {
if (!fetch) {
fetch = getFetch();
export class FetchHttpClient implements HttpClient {
public async send(request: HttpRequest): Promise<HttpResponse> {
let result: Promise<HttpResponse>;
try {
const fetchRequestOptions: RequestInit = {
method: request.httpMethod,
headers: request.headers.toJson(),
body: request.body
};
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 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;
}
let result: Promise<HttpResponse>;
try {
const fetchRequestOptions: RequestInit = {
method: request.httpMethod,
headers: request.headers.toJson(),
body: request.body
};
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 response: HttpResponse = {
request: request,
statusCode: fetchResponse.status,
headers: responseHeaders,
bodyAsText: () => fetchResponse.text(),
bodyAsJson: () => fetchResponse.json()
};
result = Promise.resolve(response);
} catch (err) {
result = Promise.reject(err);
}
return result;
}

Просмотреть файл

@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
import { RequestPolicy } from "./requestPolicy";
/**
* A function that can send HttpRequests and receive promised HttpResponses.
* @param request The HTTP request to send.
* @returns A Promise that resolves to the HttpResponse from the targeted server.
*/
export type HttpClient = (request: HttpRequest) => Promise<HttpResponse>;
export interface HttpClient extends RequestPolicy {
}

Просмотреть файл

@ -1,18 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpClient } from "./httpClient";
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
import { RequestPolicy } from "./requestPolicy";
/**
* An adapter type that adapts a HttpClient to look like a RequestPolicy.
*/
export class HttpClientToRequestPolicyAdapter implements RequestPolicy {
constructor(private _httpClient: HttpClient) {
}
send(request: HttpRequest): Promise<HttpResponse> {
return this._httpClient(request);
}
}

Просмотреть файл

@ -32,10 +32,10 @@ export type RawHttpHeaders = { [headerName: string]: string };
* A collection of HTTP header key/value pairs.
*/
export class HttpHeaders {
private _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;
}

Просмотреть файл

@ -1,4 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
export type HttpMethod = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
/**
* The different HttpMethods that can be associated with a HttpRequest.
*/
export enum HttpMethod {
GET = "GET",
PUT = "PUT",
POST = "POST",
DELETE = "DELETE",
PATCH = "PATCH",
HEAD = "HEAD",
OPTIONS = "OPTIONS",
TRACE = "TRACE"
}

Просмотреть файл

@ -1,8 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { fetchHttpClient } from "./fetchHttpClient";
import { FetchHttpClient } from "./fetchHttpClient";
import { HttpClient } from "./httpClient";
import { HttpClientToRequestPolicyAdapter } from "./httpClientToRequestPolicyAdapter";
import { HttpPipelineOptions } from "./httpPipelineOptions";
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
@ -14,7 +13,7 @@ let defaultHttpClient: HttpClient;
function getDefaultHttpClient(): HttpClient {
if (!defaultHttpClient) {
defaultHttpClient = fetchHttpClient;
defaultHttpClient = new FetchHttpClient();
}
return defaultHttpClient;
}
@ -24,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 _requestPolicyFactories: RequestPolicyFactory[], private _options: HttpPipelineOptions) {
if (!this._options) {
this._options = {};
constructor(private readonly requestPolicyFactories: RequestPolicyFactory[], private readonly options: HttpPipelineOptions) {
if (!this.options) {
this.options = {};
}
if (!this._options.httpClient) {
this._options.httpClient = getDefaultHttpClient();
if (!this.options.httpClient) {
this.options.httpClient = getDefaultHttpClient();
}
this._httpClient = this._options.httpClient;
this._requestPolicyOptions = new RequestPolicyOptions(this._options.pipelineLogger);
this.httpClient = this.options.httpClient;
this.requestPolicyOptions = new RequestPolicyOptions(this.options.pipelineLogger);
}
/**
@ -46,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 = new HttpClientToRequestPolicyAdapter(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);

Просмотреть файл

@ -24,34 +24,4 @@ export enum HttpPipelineLogLevel {
* An information log.
*/
INFO
}
/**
* Convert the provided HttpPipelineLogLevel to its string representation.
* @param logLevel The HttpPipelineLogLevel to convert to a string.
* @returns The string representation of the provided HttpPipelineLogLevel.
*/
export function httpPipelineLogLevelToString(logLevel: HttpPipelineLogLevel): string {
let result: string;
switch (logLevel) {
case HttpPipelineLogLevel.ERROR:
result = "ERROR";
break;
case HttpPipelineLogLevel.INFO:
result = "INFO";
break;
case HttpPipelineLogLevel.OFF:
result = "OFF";
break;
case HttpPipelineLogLevel.WARNING:
result = "WARNING";
break;
default:
throw new Error(`Unrecognized HttpPipelineLogLevel: ${logLevel}`);
}
return result;
}

Просмотреть файл

@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpPipelineLogLevel, httpPipelineLogLevelToString } from "./httpPipelineLogLevel";
import { HttpPipelineLogLevel } from "./httpPipelineLogLevel";
/**
* A Logger that can be added to a HttpPipeline. This enables each RequestPolicy to log messages
@ -28,23 +28,11 @@ export interface HttpPipelineLogger {
* A HttpPipelineLogger that will send its logs to the console.
*/
export class ConsoleHttpPipelineLogger implements HttpPipelineLogger {
constructor(private _minimumLogLevel: HttpPipelineLogLevel) {
}
/**
* The log level threshold for what logs will be logged.
* @return The log level threshold for what logs will be logged.
* Create a new ConsoleHttpPipelineLogger.
* @param minimumLogLevel The log level threshold for what logs will be logged.
*/
public get minimumLogLevel(): HttpPipelineLogLevel {
return this._minimumLogLevel;
}
/**
* Set the log level threshold for what logs will be logged.
* @param The new minimum log level.
*/
public set minimumLogLevel(minimumLogLevel: HttpPipelineLogLevel) {
this._minimumLogLevel = minimumLogLevel;
constructor(public minimumLogLevel: HttpPipelineLogLevel) {
}
/**
@ -55,7 +43,6 @@ export class ConsoleHttpPipelineLogger implements HttpPipelineLogger {
* provided message.
*/
log(logLevel: HttpPipelineLogLevel, message: string): void {
const logLevelString: string = httpPipelineLogLevelToString(logLevel);
console.log(`${logLevelString}: ${message}`);
console.log(`${HttpPipelineLogLevel[logLevel]}: ${message}`);
}
}

Просмотреть файл

@ -45,4 +45,11 @@ export class HttpRequest {
public get body(): string | undefined {
return this._body;
}
/**
* Create a deep clone/copy of this HttpRequest.
*/
public clone(): HttpRequest {
return JSON.parse(JSON.stringify(this));
}
}

Просмотреть файл

@ -26,10 +26,10 @@ export interface HttpResponse {
/**
* Get the body of this HttpResponse as a string.
*/
bodyAsText(): Promise<string | undefined>;
textBody(): Promise<string | undefined>;
/**
* Get the body of this HttpResponse as a JSON object.
* Get the body of this HttpResponse after it has been deserialized.
*/
bodyAsJson(): Promise<{} | any[] | undefined>;
deserializedBody(): Promise<any>;
}

Просмотреть файл

@ -11,22 +11,22 @@ import { RequestPolicyOptions } from "../requestPolicyOptions";
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
*/
export function userAgentRequestPolicyFactory(userAgent: string): RequestPolicyFactory {
export function userAgentPolicy(userAgent: string): RequestPolicyFactory {
return (nextPolicy: RequestPolicy, options: RequestPolicyOptions) => {
return new UserAgentRequestPolicy(userAgent, nextPolicy, options);
return new UserAgentPolicy(userAgent, nextPolicy, options);
};
}
class UserAgentRequestPolicy extends BaseRequestPolicy {
constructor(private _userAgent: string, nextPolicy: RequestPolicy, options: RequestPolicyOptions) {
class UserAgentPolicy extends BaseRequestPolicy {
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);
request.headers.set("User-Agent", this.userAgent);
return this.nextPolicy.send(request);
}
}

Просмотреть файл

@ -23,25 +23,18 @@ export interface RequestPolicy {
* A base class implementation of RequestPolicy.
*/
export abstract class BaseRequestPolicy implements RequestPolicy {
constructor(private _nextPolicy: RequestPolicy, private _options: RequestPolicyOptions) {
constructor(protected readonly nextPolicy: RequestPolicy, private readonly options: RequestPolicyOptions) {
}
public abstract send(request: HttpRequest): Promise<HttpResponse>;
/**
* The next RequestPolicy in the HttpPipeline.
*/
protected get nextPolicy(): RequestPolicy {
return this._nextPolicy;
}
/**
* Get whether or not a log with the provided log level should be logged.
* @param logLevel The log level of the log that will be logged.
* @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);
}
/**
@ -51,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);
}
}

24
test/fakeHttpClient.ts Normal file
Просмотреть файл

@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpClient } from "../lib/httpClient";
import { HttpRequest } from "../lib/httpRequest";
import { HttpResponse } from "../lib/httpResponse";
/**
* A function that can send HttpRequests and receive promised HttpResponses.
* @param request The HTTP request to send.
* @returns A Promise that resolves to the HttpResponse from the targeted server.
*/
export class FakeHttpClient implements HttpClient {
constructor(private readonly sendFunction: (request: HttpRequest) => Promise<HttpResponse>) {
}
/**
* Send the provided HttpRequest and return a Promise that resolves to the HttpResponse from the
* targeted server.
* @param request The HttpRequest to send.
*/
public send(request: HttpRequest): Promise<HttpResponse> {
return this.sendFunction(request);
}
}

Просмотреть файл

@ -1,31 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import { fetchHttpClient } from "../lib/fetchHttpClient";
import { FetchHttpClient } from "../lib/fetchHttpClient";
import { HttpMethod } from "../lib/httpMethod";
import { HttpRequest } from "../lib/httpRequest";
import { HttpResponse } from "../lib/httpResponse";
describe("fetchHttpClient", () => {
it("should send HTTP requests", () => {
const request = new HttpRequest("GET", "http://www.example.com", {});
return fetchHttpClient(request)
.then((response: HttpResponse) => {
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");
assert.strictEqual(response.headers.get("content-type"), "text/html");
assert.strictEqual(response.headers.get("vary"), "Accept-Encoding");
it("should send HTTP requests", async () => {
const request = new HttpRequest(HttpMethod.GET, "http://www.example.com", {});
const httpClient = new FetchHttpClient();
return response.bodyAsText();
})
.then((responseBody?: string) => {
assert(responseBody);
const expectedResponseBody: string =
const response: HttpResponse = await httpClient.send(request)
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");
assert.strictEqual(response.headers.get("content-type"), "text/html");
assert.strictEqual(response.headers.get("vary"), "Accept-Encoding");
const responseBody: string | undefined = await response.textBody();
const expectedResponseBody: string =
`<!doctype html>
<html>
<head>
@ -77,7 +74,6 @@ describe("fetchHttpClient", () => {
</body>
</html>
`;
assert.strictEqual(responseBody, expectedResponseBody);
});
assert.strictEqual(responseBody, expectedResponseBody);
});
});

Просмотреть файл

@ -1,23 +0,0 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpPipelineLogLevel, httpPipelineLogLevelToString } from "../lib/httpPipelineLogLevel";
import * as assert from "assert";
describe("httpPipelineLogLevelToString()", () => {
it(`should work with ERROR`, () => {
assert.strictEqual(httpPipelineLogLevelToString(HttpPipelineLogLevel.ERROR), "ERROR");
});
it(`should work with INFO`, () => {
assert.strictEqual(httpPipelineLogLevelToString(HttpPipelineLogLevel.INFO), "INFO");
});
it(`should work with WARNING`, () => {
assert.strictEqual(httpPipelineLogLevelToString(HttpPipelineLogLevel.WARNING), "WARNING");
});
it(`should work with OFF`, () => {
assert.strictEqual(httpPipelineLogLevelToString(HttpPipelineLogLevel.OFF), "OFF");
});
});

Просмотреть файл

@ -2,70 +2,64 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import { HttpClient } from "../lib/httpClient";
import { HttpMethod } from "../lib/httpMethod";
import { HttpPipeline } from "../lib/httpPipeline";
import { HttpRequest } from "../lib/httpRequest";
import { HttpResponse } from "../lib/httpResponse";
import { userAgentRequestPolicyFactory } from "../lib/policies/userAgentRequestPolicyFactory";
import { userAgentPolicy } from "../lib/policies/userAgentPolicy";
import { BaseRequestPolicy } from "../lib/requestPolicy";
import { FakeHttpClient } from "./fakeHttpClient";
import { InMemoryHttpResponse } from "./inMemoryHttpResponse";
describe("HttpPipeline", () => {
it("should send requests when no request policies are assigned", () => {
const httpClient: HttpClient = (request: HttpRequest) => {
it("should send requests when no request policies are assigned", async () => {
const httpClient: HttpClient = new FakeHttpClient((request: HttpRequest) => {
return Promise.resolve(new InMemoryHttpResponse(request, 200, {}, "hello"));
};
});
const httpPipeline = new HttpPipeline([], { httpClient: httpClient });
const httpRequest = new HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then((response: HttpResponse) => {
assert.deepStrictEqual(response.request, httpRequest);
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return response.bodyAsText();
})
.then((responseBodyAsText: string | undefined) => {
assert.strictEqual("hello", responseBodyAsText);
});
const httpRequest = new HttpRequest(HttpMethod.GET, "http://www.example.com", {});
const response: HttpResponse = await httpPipeline.send(httpRequest);
assert.deepStrictEqual(response.request, httpRequest);
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
const responseBodyAsText: string | undefined = await response.textBody();
assert.strictEqual("hello", responseBodyAsText);
});
it("should send requests when request-modifying request policies are assigned", () => {
const httpClient: HttpClient = (request: HttpRequest) => {
it("should send requests when request-modifying request policies are assigned", async () => {
const httpClient: HttpClient = new FakeHttpClient((request: HttpRequest) => {
assert.deepStrictEqual(request.headers.toJson(), { "User-Agent": "my user agent string" });
return Promise.resolve(new InMemoryHttpResponse(request, 200, {}, "hello2"));
};
});
const httpPipeline = new HttpPipeline(
[ userAgentRequestPolicyFactory("my user agent string") ],
[ userAgentPolicy("my user agent string") ],
{ httpClient: httpClient });
const httpRequest = new HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then((response: HttpResponse) => {
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), { "User-Agent": "my user agent string" });
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
return response.bodyAsText();
})
.then((responseBodyAsText: string | undefined) => {
assert.strictEqual("hello2", responseBodyAsText);
});
const httpRequest = new HttpRequest(HttpMethod.GET, "http://www.example.com", {});
const response: HttpResponse = await httpPipeline.send(httpRequest);
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), { "User-Agent": "my user agent string" });
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {});
const responseBodyAsText: string | undefined = await response.textBody();
assert.strictEqual("hello2", responseBodyAsText);
});
it("should send requests when response-modifying request policies are assigned", () => {
const httpClient: HttpClient = (request: HttpRequest) => {
it("should send requests when response-modifying request policies are assigned", async () => {
const httpClient: HttpClient = new FakeHttpClient((request: HttpRequest) => {
assert.deepStrictEqual(request.headers.toJson(), {});
return Promise.resolve(new InMemoryHttpResponse(request, 200, {}, "hello3"));
};
});
class ResponseModifyingRequestPolicy extends BaseRequestPolicy {
send(request: HttpRequest): Promise<HttpResponse> {
return this.nextPolicy.send(request).then((response: HttpResponse) => {
response.headers.set("My-Header", "My-Value");
return response;
});
public async send(request: HttpRequest): Promise<HttpResponse> {
const response: HttpResponse = await this.nextPolicy.send(request);
response.headers.set("My-Header", "My-Value");
return response;
}
}
@ -73,17 +67,13 @@ describe("HttpPipeline", () => {
[ (nextPolicy, options) => new ResponseModifyingRequestPolicy(nextPolicy, options) ],
{ httpClient: httpClient });
const httpRequest = new HttpRequest("GET", "http://www.example.com", {});
return httpPipeline.send(httpRequest)
.then((response: HttpResponse) => {
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), {});
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {"My-Header": "My-Value"});
return response.bodyAsText();
})
.then((responseBodyAsText: string | undefined) => {
assert.strictEqual("hello3", responseBodyAsText);
});
const httpRequest = new HttpRequest(HttpMethod.GET, "http://www.example.com", {});
const response: HttpResponse = await httpPipeline.send(httpRequest);
assert.deepStrictEqual(response.request, httpRequest);
assert.deepStrictEqual(response.request.headers.toJson(), {});
assert.strictEqual(response.statusCode, 200);
assert.deepStrictEqual(response.headers.toJson(), {"My-Header": "My-Value"});
const responseBodyAsText: string | undefined = await response.textBody();
assert.strictEqual("hello3", responseBodyAsText);
});
});

Просмотреть файл

@ -1,13 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import { HttpMethod } from "../lib/httpMethod";
import { HttpRequest } from "../lib/httpRequest";
describe("HttpRequest", () => {
describe("constructor", () => {
it(`should throw an Error when the url is ""`, () => {
try {
new HttpRequest("GET", "", {});
new HttpRequest(HttpMethod.GET, "", {});
assert.fail("Should have thrown an error.");
} catch (error) {
assert.notEqual(error, null);
@ -16,32 +17,32 @@ describe("HttpRequest", () => {
});
it(`should return a valid GET HttpRequest when the url is "www.example.com"`, () => {
const httpRequest: HttpRequest = new HttpRequest("GET", "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, "GET");
const httpRequest: HttpRequest = new HttpRequest(HttpMethod.GET, "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, HttpMethod.GET);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, undefined);
});
it(`should return a valid POST HttpRequest when the body is undefined`, () => {
const httpRequest: HttpRequest = new HttpRequest("POST", "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, "POST");
const httpRequest: HttpRequest = new HttpRequest(HttpMethod.POST, "www.example.com", {});
assert.strictEqual(httpRequest.httpMethod, HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, undefined);
});
it(`should return a valid POST HttpRequest when the body is ""`, () => {
const httpRequest: HttpRequest = new HttpRequest("POST", "www.example.com", {}, "");
assert.strictEqual(httpRequest.httpMethod, "POST");
const httpRequest: HttpRequest = new HttpRequest(HttpMethod.POST, "www.example.com", {}, "");
assert.strictEqual(httpRequest.httpMethod, HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {});
assert.strictEqual(httpRequest.body, "");
});
it(`should return a valid POST HttpRequest when the body is "hello"`, () => {
const httpRequest: HttpRequest = new HttpRequest("POST", "www.example.com", {"Content-Length": "5"}, "hello");
assert.strictEqual(httpRequest.httpMethod, "POST");
const httpRequest: HttpRequest = new HttpRequest(HttpMethod.POST, "www.example.com", {"Content-Length": "5"}, "hello");
assert.strictEqual(httpRequest.httpMethod, HttpMethod.POST);
assert.strictEqual(httpRequest.url, "www.example.com");
assert.deepStrictEqual(httpRequest.headers.toJson(), {"Content-Length": "5"});
assert.strictEqual(httpRequest.body, "hello");

Просмотреть файл

@ -1,8 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import { HttpPipelineLogLevel } from "../lib/httpPipelineLogLevel";
import { HttpPipelineLogger } from "../lib/httpPipelineLogger";
import { HttpPipelineLogLevel, httpPipelineLogLevelToString } from "../lib/httpPipelineLogLevel";
/**
* An in-memory HttpPipelineLogger that can be used for testing.
@ -30,7 +29,6 @@ export class InMemoryHttpPipelineLogger implements HttpPipelineLogger {
}
public log(logLevel: HttpPipelineLogLevel, message: string): void {
const logLevelString: string = httpPipelineLogLevelToString(logLevel);
this._logs.push(`${logLevelString}: ${message}`);
this._logs.push(`${HttpPipelineLogLevel[logLevel]}: ${message}`);
}
}

Просмотреть файл

@ -23,10 +23,10 @@ export class InMemoryHttpResponse implements HttpResponse {
return this._headers;
}
bodyAsText(): Promise<string | undefined> {
textBody(): Promise<string | undefined> {
return Promise.resolve(this._bodyText);
}
bodyAsJson(): Promise<{} | any[] | undefined> {
deserializedBody(): Promise<{} | any[] | undefined> {
return Promise.resolve(this._bodyText ? JSON.parse(this._bodyText) : undefined);
}
}

Просмотреть файл

@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
import * as assert from "assert";
import { HttpMethod } from "../../lib/httpMethod";
import { HttpRequest } from "../../lib/httpRequest";
import { HttpResponse } from "../../lib/httpResponse";
import { userAgentPolicy } from "../../lib/policies/userAgentPolicy";
import { RequestPolicy } from "../../lib/requestPolicy";
import { RequestPolicyFactory } from "../../lib/requestPolicyFactory";
import { RequestPolicyOptions } from "../../lib/requestPolicyOptions";
import { InMemoryHttpResponse } from "../inMemoryHttpResponse";
describe("userAgentPolicy", () => {
it("assigns the 'User-Agent' header to requests and does nothing to responses", async () => {
const policyFactory: RequestPolicyFactory = userAgentPolicy("my-user-agent-string");
const nextPolicy: RequestPolicy = {
send: (request: HttpRequest) => {
return Promise.resolve(new InMemoryHttpResponse(request, 200, {}));
}
}
const policy: RequestPolicy = policyFactory(nextPolicy, new RequestPolicyOptions());
const request = new HttpRequest(HttpMethod.GET, "https://spam.com", {});
const response: HttpResponse = await policy.send(request);
assert.deepStrictEqual(request, new HttpRequest(HttpMethod.GET, "https://spam.com", {"User-Agent": "my-user-agent-string"}));
assert.deepStrictEqual(response.request, new HttpRequest(HttpMethod.GET, "https://spam.com", {"User-Agent": "my-user-agent-string"}));
});
});

6
typings/lib/fetchHttpClient.d.ts поставляемый
Просмотреть файл

@ -1,7 +1,9 @@
import { HttpClient } from "./httpClient";
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
/**
* A HttpClient implementation that uses fetch to send HTTP requests.
* @param request The request to send.
*/
export declare function fetchHttpClient(request: HttpRequest): Promise<HttpResponse>;
export declare class FetchHttpClient implements HttpClient {
send(request: HttpRequest): Promise<HttpResponse>;
}

6
typings/lib/httpClient.d.ts поставляемый
Просмотреть файл

@ -1,8 +1,8 @@
import { HttpRequest } from "./httpRequest";
import { HttpResponse } from "./httpResponse";
import { RequestPolicy } from "./requestPolicy";
/**
* A function that can send HttpRequests and receive promised HttpResponses.
* @param request The HTTP request to send.
* @returns A Promise that resolves to the HttpResponse from the targeted server.
*/
export declare type HttpClient = (request: HttpRequest) => Promise<HttpResponse>;
export interface HttpClient extends RequestPolicy {
}

2
typings/lib/httpHeaders.d.ts поставляемый
Просмотреть файл

@ -21,7 +21,7 @@ export declare type RawHttpHeaders = {
* A collection of HTTP header key/value pairs.
*/
export declare class HttpHeaders {
private _headersMap;
private readonly headersMap;
constructor(rawHeaders?: RawHttpHeaders);
/**
* Set a header in this collection with the provided name and value. The name is

14
typings/lib/httpMethod.d.ts поставляемый
Просмотреть файл

@ -1 +1,13 @@
export declare type HttpMethod = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
/**
* The different HttpMethods that can be associated with a HttpRequest.
*/
export declare enum HttpMethod {
GET = "GET",
PUT = "PUT",
POST = "POST",
DELETE = "DELETE",
PATCH = "PATCH",
HEAD = "HEAD",
OPTIONS = "OPTIONS",
TRACE = "TRACE",
}

10
typings/lib/httpPipeline.d.ts поставляемый
Просмотреть файл

@ -7,11 +7,11 @@ import { RequestPolicyFactory } from "./requestPolicyFactory";
* be applied to a HTTP response when it is received.
*/
export declare class HttpPipeline {
private _requestPolicyFactories;
private _options;
private readonly _httpClient;
private readonly _requestPolicyOptions;
constructor(_requestPolicyFactories: RequestPolicyFactory[], _options: HttpPipelineOptions);
private readonly requestPolicyFactories;
private readonly options;
private readonly httpClient;
private readonly requestPolicyOptions;
constructor(requestPolicyFactories: RequestPolicyFactory[], options: HttpPipelineOptions);
/**
* Send the provided HttpRequest request.
* @param request The HTTP request to send.

6
typings/lib/httpPipelineLogLevel.d.ts поставляемый
Просмотреть файл

@ -19,9 +19,3 @@ export declare enum HttpPipelineLogLevel {
*/
INFO = 3,
}
/**
* Convert the provided HttpPipelineLogLevel to its string representation.
* @param logLevel The HttpPipelineLogLevel to convert to a string.
* @returns The string representation of the provided HttpPipelineLogLevel.
*/
export declare function httpPipelineLogLevelToString(logLevel: HttpPipelineLogLevel): string;

15
typings/lib/httpPipelineLogger.d.ts поставляемый
Просмотреть файл

@ -22,17 +22,12 @@ export interface HttpPipelineLogger {
* A HttpPipelineLogger that will send its logs to the console.
*/
export declare class ConsoleHttpPipelineLogger implements HttpPipelineLogger {
private _minimumLogLevel;
constructor(_minimumLogLevel: HttpPipelineLogLevel);
/**
* The log level threshold for what logs will be logged.
* @return The log level threshold for what logs will be logged.
*/
/**
* Set the log level threshold for what logs will be logged.
* @param The new minimum log level.
*/
minimumLogLevel: HttpPipelineLogLevel;
/**
* Create a new ConsoleHttpPipelineLogger.
* @param minimumLogLevel The log level threshold for what logs will be logged.
*/
constructor(minimumLogLevel: HttpPipelineLogLevel);
/**
* Log the provided message.
* @param logLevel The HttpLogDetailLevel associated with this message.

4
typings/lib/httpRequest.d.ts поставляемый
Просмотреть файл

@ -25,4 +25,8 @@ export declare class HttpRequest {
* Get the body that will be sent with this request.
*/
readonly body: string | undefined;
/**
* Create a deep clone/copy of this HttpRequest.
*/
clone(): HttpRequest;
}

6
typings/lib/httpResponse.d.ts поставляемый
Просмотреть файл

@ -19,9 +19,9 @@ export interface HttpResponse {
/**
* Get the body of this HttpResponse as a string.
*/
bodyAsText(): Promise<string | undefined>;
textBody(): Promise<string | undefined>;
/**
* Get the body of this HttpResponse as a JSON object.
* Get the body of this HttpResponse after it has been deserialized.
*/
bodyAsJson(): Promise<{} | any[] | undefined>;
deserializedBody(): Promise<any>;
}

6
typings/lib/policies/userAgentPolicy.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { RequestPolicyFactory } from "../requestPolicyFactory";
/**
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
*/
export declare function userAgentPolicy(userAgent: string): RequestPolicyFactory;

6
typings/lib/policies/userAgentPolicyFactory.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,6 @@
import { RequestPolicyFactory } from "../requestPolicyFactory";
/**
* Get a RequestPolicyFactory that creates UserAgentRequestPolicies.
* @param userAgent The userAgent string to apply to each outgoing request.
*/
export declare function userAgentPolicyFactory(userAgent: string): RequestPolicyFactory;

10
typings/lib/requestPolicy.d.ts поставляемый
Просмотреть файл

@ -18,14 +18,10 @@ export interface RequestPolicy {
* A base class implementation of RequestPolicy.
*/
export declare abstract class BaseRequestPolicy implements RequestPolicy {
private _nextPolicy;
private _options;
constructor(_nextPolicy: RequestPolicy, _options: RequestPolicyOptions);
abstract send(request: HttpRequest): Promise<HttpResponse>;
/**
* The next RequestPolicy in the HttpPipeline.
*/
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.
* @param logLevel The log level of the log that will be logged.

18
typings/test/fakeHttpClient.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,18 @@
import { HttpClient } from "../lib/httpClient";
import { HttpRequest } from "../lib/httpRequest";
import { HttpResponse } from "../lib/httpResponse";
/**
* A function that can send HttpRequests and receive promised HttpResponses.
* @param request The HTTP request to send.
* @returns A Promise that resolves to the HttpResponse from the targeted server.
*/
export declare class FakeHttpClient implements HttpClient {
private readonly sendFunction;
constructor(sendFunction: (request: HttpRequest) => Promise<HttpResponse>);
/**
* Send the provided HttpRequest and return a Promise that resolves to the HttpResponse from the
* targeted server.
* @param request The HttpRequest to send.
*/
send(request: HttpRequest): Promise<HttpResponse>;
}

Просмотреть файл

@ -1,5 +1,5 @@
import { HttpPipelineLogger } from "../lib/httpPipelineLogger";
import { HttpPipelineLogLevel } from "../lib/httpPipelineLogLevel";
import { HttpPipelineLogger } from "../lib/httpPipelineLogger";
/**
* An in-memory HttpPipelineLogger that can be used for testing.
*/

8
typings/test/inMemoryHttpResponse.d.ts поставляемый
Просмотреть файл

@ -1,6 +1,6 @@
import { HttpResponse } from "../lib/httpResponse";
import { HttpRequest } from "../lib/httpRequest";
import { HttpHeaders, RawHttpHeaders } from "../lib/httpHeaders";
import { HttpRequest } from "../lib/httpRequest";
import { HttpResponse } from "../lib/httpResponse";
export declare class InMemoryHttpResponse implements HttpResponse {
private _request;
private _statusCode;
@ -10,6 +10,6 @@ export declare class InMemoryHttpResponse implements HttpResponse {
readonly request: HttpRequest;
readonly statusCode: number;
readonly headers: HttpHeaders;
bodyAsText(): Promise<string | undefined>;
bodyAsJson(): Promise<{} | any[] | undefined>;
textBody(): Promise<string | undefined>;
deserializedBody(): Promise<{} | any[] | undefined>;
}

1
typings/test/policies/userAgentPolicyTests.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
export {};