1 |
|
2 |
|
3 | import { __extends } from "tslib";
|
4 | import { HttpHeaders } from "../httpHeaders";
|
5 | import { Constants } from "../util/constants";
|
6 | import { getDefaultUserAgentKey, getPlatformSpecificData } from "./msRestUserAgentPolicy";
|
7 | import { BaseRequestPolicy, } from "./requestPolicy";
|
8 | function getRuntimeInfo() {
|
9 | var msRestRuntime = {
|
10 | key: "ms-rest-js",
|
11 | value: Constants.msRestVersion,
|
12 | };
|
13 | return [msRestRuntime];
|
14 | }
|
15 | function getUserAgentString(telemetryInfo, keySeparator, valueSeparator) {
|
16 | if (keySeparator === void 0) { keySeparator = " "; }
|
17 | if (valueSeparator === void 0) { valueSeparator = "/"; }
|
18 | return telemetryInfo
|
19 | .map(function (info) {
|
20 | var value = info.value ? "" + valueSeparator + info.value : "";
|
21 | return "" + info.key + value;
|
22 | })
|
23 | .join(keySeparator);
|
24 | }
|
25 | export var getDefaultUserAgentHeaderName = getDefaultUserAgentKey;
|
26 | export function getDefaultUserAgentValue() {
|
27 | var runtimeInfo = getRuntimeInfo();
|
28 | var platformSpecificData = getPlatformSpecificData();
|
29 | var userAgent = getUserAgentString(runtimeInfo.concat(platformSpecificData));
|
30 | return userAgent;
|
31 | }
|
32 | export function userAgentPolicy(userAgentData) {
|
33 | var key = !userAgentData || userAgentData.key == undefined ? getDefaultUserAgentKey() : userAgentData.key;
|
34 | var value = !userAgentData || userAgentData.value == undefined
|
35 | ? getDefaultUserAgentValue()
|
36 | : userAgentData.value;
|
37 | return {
|
38 | create: function (nextPolicy, options) {
|
39 | return new UserAgentPolicy(nextPolicy, options, key, value);
|
40 | },
|
41 | };
|
42 | }
|
43 | var UserAgentPolicy = (function (_super) {
|
44 | __extends(UserAgentPolicy, _super);
|
45 | function UserAgentPolicy(_nextPolicy, _options, headerKey, headerValue) {
|
46 | var _this = _super.call(this, _nextPolicy, _options) || this;
|
47 | _this._nextPolicy = _nextPolicy;
|
48 | _this._options = _options;
|
49 | _this.headerKey = headerKey;
|
50 | _this.headerValue = headerValue;
|
51 | return _this;
|
52 | }
|
53 | UserAgentPolicy.prototype.sendRequest = function (request) {
|
54 | this.addUserAgentHeader(request);
|
55 | return this._nextPolicy.sendRequest(request);
|
56 | };
|
57 | UserAgentPolicy.prototype.addUserAgentHeader = function (request) {
|
58 | if (!request.headers) {
|
59 | request.headers = new HttpHeaders();
|
60 | }
|
61 | if (!request.headers.get(this.headerKey) && this.headerValue) {
|
62 | request.headers.set(this.headerKey, this.headerValue);
|
63 | }
|
64 | };
|
65 | return UserAgentPolicy;
|
66 | }(BaseRequestPolicy));
|
67 | export { UserAgentPolicy };
|
68 |
|
\ | No newline at end of file |