myenergi-api 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Digest.d.ts +1 -0
- package/dist/src/Digest.js +9 -2
- package/package.json +1 -1
package/dist/src/Digest.d.ts
CHANGED
package/dist/src/Digest.js
CHANGED
|
@@ -28,6 +28,7 @@ const https = __importStar(require("https"));
|
|
|
28
28
|
const AuthDigest_1 = require("./AuthDigest");
|
|
29
29
|
class Digest {
|
|
30
30
|
constructor(baseUrl, username, password) {
|
|
31
|
+
this._etags = {};
|
|
31
32
|
this._maxRedirectCount = 3;
|
|
32
33
|
this._maxRetryCount = 2;
|
|
33
34
|
this._baseUrl = new URL(baseUrl);
|
|
@@ -42,9 +43,13 @@ class Digest {
|
|
|
42
43
|
if (!options.headers)
|
|
43
44
|
options.headers = {};
|
|
44
45
|
options.headers.Authorization = (_a = this._authDigest) === null || _a === void 0 ? void 0 : _a.getAuthorization(options.method, options.path);
|
|
46
|
+
const etag = this._etags[options.path];
|
|
47
|
+
if (etag)
|
|
48
|
+
options.headers["If-None-Match"] = etag;
|
|
45
49
|
const req = https.request(options, (res) => {
|
|
46
50
|
var _a, _b;
|
|
47
51
|
if (res.statusCode == 401) {
|
|
52
|
+
this._etags[options.path] = res.headers.etag;
|
|
48
53
|
const myenergiAsn = res.headers["x_myenergi-asn"];
|
|
49
54
|
if (myenergiAsn && myenergiAsn !== "undefined" && myenergiAsn !== this._baseUrl.host) {
|
|
50
55
|
if (redirectCount > this._maxRedirectCount) {
|
|
@@ -115,6 +120,10 @@ class Digest {
|
|
|
115
120
|
});
|
|
116
121
|
}
|
|
117
122
|
else if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400) {
|
|
123
|
+
if (res.statusCode == 304) {
|
|
124
|
+
resolve("{}");
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
118
127
|
if (redirectCount > this._maxRedirectCount) {
|
|
119
128
|
reject(`Too many redirects: ${res.headers["location"]}`);
|
|
120
129
|
return;
|
|
@@ -134,13 +143,11 @@ class Digest {
|
|
|
134
143
|
});
|
|
135
144
|
}
|
|
136
145
|
else {
|
|
137
|
-
console.error("status code failed!!");
|
|
138
146
|
reject("status code failed!!");
|
|
139
147
|
return;
|
|
140
148
|
}
|
|
141
149
|
});
|
|
142
150
|
req.on("error", (e) => {
|
|
143
|
-
console.error(`problem with request: ${e.message}`);
|
|
144
151
|
reject(e);
|
|
145
152
|
});
|
|
146
153
|
if (data) {
|
package/package.json
CHANGED