@mswjs/interceptors 0.25.12 → 0.25.13
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/lib/browser/{chunk-7II4SWKS.mjs → chunk-3YG2666Q.mjs} +14 -1
- package/lib/browser/{chunk-3LFH2WCF.js → chunk-3ZL2Y3NK.js} +14 -1
- package/lib/browser/{chunk-XIARBQ4Q.js → chunk-4X6R3LBU.js} +6 -10
- package/lib/browser/{chunk-PYOA2PFX.mjs → chunk-XILA3UPG.mjs} +3 -7
- package/lib/browser/index.d.ts +7 -1
- package/lib/browser/index.js +4 -2
- package/lib/browser/index.mjs +5 -3
- package/lib/browser/interceptors/XMLHttpRequest/index.js +3 -3
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +2 -2
- package/lib/browser/presets/browser.js +3 -3
- package/lib/browser/presets/browser.mjs +2 -2
- package/lib/node/RemoteHttpInterceptor.js +5 -5
- package/lib/node/RemoteHttpInterceptor.mjs +3 -3
- package/lib/node/{chunk-B7VH2MOR.js → chunk-5OKLCEIP.js} +2 -4
- package/lib/node/chunk-5XLKQVVL.mjs +15 -0
- package/lib/node/{chunk-N65JTHKK.js → chunk-EORE2RV6.js} +2 -4
- package/lib/node/{chunk-Z26AUTER.mjs → chunk-OVITJLTK.mjs} +3 -5
- package/lib/node/chunk-TSYVWURF.js +15 -0
- package/lib/node/{chunk-N5ZHB3BO.mjs → chunk-V3QPQ45S.mjs} +3 -5
- package/lib/node/index.d.ts +7 -1
- package/lib/node/index.js +5 -1
- package/lib/node/index.mjs +5 -1
- package/lib/node/interceptors/ClientRequest/index.js +3 -3
- package/lib/node/interceptors/ClientRequest/index.mjs +2 -2
- package/lib/node/interceptors/XMLHttpRequest/index.js +3 -3
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +2 -2
- package/lib/node/presets/node.js +5 -5
- package/lib/node/presets/node.mjs +3 -3
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/interceptors/ClientRequest/utils/createResponse.test.ts +10 -2
- package/src/interceptors/ClientRequest/utils/createResponse.ts +2 -4
- package/src/interceptors/XMLHttpRequest/utils/createResponse.ts +2 -6
- package/src/utils/responseUtils.ts +11 -1
- package/lib/node/chunk-3IYIKC3X.mjs +0 -6
- package/lib/node/chunk-OGN3ZR35.js +0 -6
|
@@ -14,8 +14,21 @@ function toArrayBuffer(array) {
|
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// src/utils/responseUtils.ts
|
|
18
|
+
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
19
|
+
101,
|
|
20
|
+
103,
|
|
21
|
+
204,
|
|
22
|
+
205,
|
|
23
|
+
304
|
|
24
|
+
]);
|
|
25
|
+
function isResponseWithoutBody(status) {
|
|
26
|
+
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
27
|
+
}
|
|
28
|
+
|
|
17
29
|
export {
|
|
18
30
|
encodeBuffer,
|
|
19
31
|
decodeBuffer,
|
|
20
|
-
toArrayBuffer
|
|
32
|
+
toArrayBuffer,
|
|
33
|
+
isResponseWithoutBody
|
|
21
34
|
};
|
|
@@ -14,8 +14,21 @@ function toArrayBuffer(array) {
|
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
// src/utils/responseUtils.ts
|
|
18
|
+
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
19
|
+
101,
|
|
20
|
+
103,
|
|
21
|
+
204,
|
|
22
|
+
205,
|
|
23
|
+
304
|
|
24
|
+
]);
|
|
25
|
+
function isResponseWithoutBody(status) {
|
|
26
|
+
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
17
30
|
|
|
18
31
|
|
|
19
32
|
|
|
20
33
|
|
|
21
|
-
exports.encodeBuffer = encodeBuffer; exports.decodeBuffer = decodeBuffer; exports.toArrayBuffer = toArrayBuffer;
|
|
34
|
+
exports.encodeBuffer = encodeBuffer; exports.decodeBuffer = decodeBuffer; exports.toArrayBuffer = toArrayBuffer; exports.isResponseWithoutBody = isResponseWithoutBody;
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
var _chunk3ZL2Y3NKjs = require('./chunk-3ZL2Y3NK.js');
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
@@ -200,14 +201,9 @@ function parseJson(data) {
|
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
// src/utils/responseUtils.ts
|
|
204
|
-
var responseStatusCodesWithoutBody = [204, 205, 304];
|
|
205
|
-
|
|
206
204
|
// src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
|
207
205
|
function createResponse(request, body) {
|
|
208
|
-
const responseBodyOrNull =
|
|
209
|
-
request.status
|
|
210
|
-
) ? null : body;
|
|
206
|
+
const responseBodyOrNull = _chunk3ZL2Y3NKjs.isResponseWithoutBody.call(void 0, request.status) ? null : body;
|
|
211
207
|
return new Response(responseBodyOrNull, {
|
|
212
208
|
status: request.status,
|
|
213
209
|
statusText: request.statusText,
|
|
@@ -289,7 +285,7 @@ var XMLHttpRequestController = class {
|
|
|
289
285
|
case "send": {
|
|
290
286
|
const [body] = args;
|
|
291
287
|
if (body != null) {
|
|
292
|
-
this.requestBody = typeof body === "string" ?
|
|
288
|
+
this.requestBody = typeof body === "string" ? _chunk3ZL2Y3NKjs.encodeBuffer.call(void 0, body) : body;
|
|
293
289
|
}
|
|
294
290
|
this.request.addEventListener("load", () => {
|
|
295
291
|
if (typeof this.onResponse !== "undefined") {
|
|
@@ -458,7 +454,7 @@ var XMLHttpRequestController = class {
|
|
|
458
454
|
}
|
|
459
455
|
}
|
|
460
456
|
responseBufferToText() {
|
|
461
|
-
return
|
|
457
|
+
return _chunk3ZL2Y3NKjs.decodeBuffer.call(void 0, this.responseBuffer);
|
|
462
458
|
}
|
|
463
459
|
get response() {
|
|
464
460
|
this.logger.info(
|
|
@@ -475,7 +471,7 @@ var XMLHttpRequestController = class {
|
|
|
475
471
|
return responseJson;
|
|
476
472
|
}
|
|
477
473
|
case "arraybuffer": {
|
|
478
|
-
const arrayBuffer =
|
|
474
|
+
const arrayBuffer = _chunk3ZL2Y3NKjs.toArrayBuffer.call(void 0, this.responseBuffer);
|
|
479
475
|
this.logger.info("resolved response ArrayBuffer", arrayBuffer);
|
|
480
476
|
return arrayBuffer;
|
|
481
477
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decodeBuffer,
|
|
3
3
|
encodeBuffer,
|
|
4
|
+
isResponseWithoutBody,
|
|
4
5
|
toArrayBuffer
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-3YG2666Q.mjs";
|
|
6
7
|
import {
|
|
7
8
|
emitAsync,
|
|
8
9
|
toInteractiveRequest,
|
|
@@ -200,14 +201,9 @@ function parseJson(data) {
|
|
|
200
201
|
}
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
// src/utils/responseUtils.ts
|
|
204
|
-
var responseStatusCodesWithoutBody = [204, 205, 304];
|
|
205
|
-
|
|
206
204
|
// src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
|
207
205
|
function createResponse(request, body) {
|
|
208
|
-
const responseBodyOrNull =
|
|
209
|
-
request.status
|
|
210
|
-
) ? null : body;
|
|
206
|
+
const responseBodyOrNull = isResponseWithoutBody(request.status) ? null : body;
|
|
211
207
|
return new Response(responseBodyOrNull, {
|
|
212
208
|
status: request.status,
|
|
213
209
|
statusText: request.statusText,
|
package/lib/browser/index.d.ts
CHANGED
|
@@ -32,4 +32,10 @@ declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
|
|
|
32
32
|
declare function encodeBuffer(text: string): Uint8Array;
|
|
33
33
|
declare function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string;
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Returns a boolean indicating whether the given response status
|
|
37
|
+
* code represents a response that cannot have a body.
|
|
38
|
+
*/
|
|
39
|
+
declare function isResponseWithoutBody(status: number): boolean;
|
|
40
|
+
|
|
41
|
+
export { BatchInterceptor, BatchInterceptorOptions, ExtractEventMapType, ExtractEventNames, Interceptor, decodeBuffer, encodeBuffer, getCleanUrl, isResponseWithoutBody };
|
package/lib/browser/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
var _chunk3ZL2Y3NKjs = require('./chunk-3ZL2Y3NK.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
@@ -67,4 +68,5 @@ function getCleanUrl(url, isAbsolute = true) {
|
|
|
67
68
|
|
|
68
69
|
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
|
|
72
|
+
exports.BatchInterceptor = BatchInterceptor; exports.IS_PATCHED_MODULE = _chunkG5ORGOKHjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkG5ORGOKHjs.Interceptor; exports.InterceptorReadyState = _chunkG5ORGOKHjs.InterceptorReadyState; exports.decodeBuffer = _chunk3ZL2Y3NKjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkG5ORGOKHjs.deleteGlobalSymbol; exports.encodeBuffer = _chunk3ZL2Y3NKjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkG5ORGOKHjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunk3ZL2Y3NKjs.isResponseWithoutBody;
|
package/lib/browser/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
decodeBuffer,
|
|
3
|
-
encodeBuffer
|
|
4
|
-
|
|
3
|
+
encodeBuffer,
|
|
4
|
+
isResponseWithoutBody
|
|
5
|
+
} from "./chunk-3YG2666Q.mjs";
|
|
5
6
|
import {
|
|
6
7
|
IS_PATCHED_MODULE,
|
|
7
8
|
Interceptor,
|
|
@@ -66,5 +67,6 @@ export {
|
|
|
66
67
|
deleteGlobalSymbol,
|
|
67
68
|
encodeBuffer,
|
|
68
69
|
getCleanUrl,
|
|
69
|
-
getGlobalSymbol
|
|
70
|
+
getGlobalSymbol,
|
|
71
|
+
isResponseWithoutBody
|
|
70
72
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var _chunk4X6R3LBUjs = require('../../chunk-4X6R3LBU.js');
|
|
4
|
+
require('../../chunk-3ZL2Y3NK.js');
|
|
5
5
|
require('../../chunk-X3NRJIZW.js');
|
|
6
6
|
require('../../chunk-G5ORGOKH.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.XMLHttpRequestInterceptor =
|
|
9
|
+
exports.XMLHttpRequestInterceptor = _chunk4X6R3LBUjs.XMLHttpRequestInterceptor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
XMLHttpRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-XILA3UPG.mjs";
|
|
4
|
+
import "../../chunk-3YG2666Q.mjs";
|
|
5
5
|
import "../../chunk-KK6APRON.mjs";
|
|
6
6
|
import "../../chunk-S72SKXXQ.mjs";
|
|
7
7
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var _chunk4X6R3LBUjs = require('../chunk-4X6R3LBU.js');
|
|
4
|
+
require('../chunk-3ZL2Y3NK.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunk5RW2GLTJjs = require('../chunk-5RW2GLTJ.js');
|
|
@@ -11,7 +11,7 @@ require('../chunk-G5ORGOKH.js');
|
|
|
11
11
|
// src/presets/browser.ts
|
|
12
12
|
var browser_default = [
|
|
13
13
|
new (0, _chunk5RW2GLTJjs.FetchInterceptor)(),
|
|
14
|
-
new (0,
|
|
14
|
+
new (0, _chunk4X6R3LBUjs.XMLHttpRequestInterceptor)()
|
|
15
15
|
];
|
|
16
16
|
|
|
17
17
|
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
var _chunkAA4NWHDYjs = require('./chunk-AA4NWHDY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkEORE2RV6js = require('./chunk-EORE2RV6.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var _chunk5OKLCEIPjs = require('./chunk-5OKLCEIP.js');
|
|
10
10
|
require('./chunk-3LFH2WCF.js');
|
|
11
|
-
require('./chunk-
|
|
11
|
+
require('./chunk-TSYVWURF.js');
|
|
12
12
|
require('./chunk-35HEWOG7.js');
|
|
13
13
|
require('./chunk-VQ4DZOBB.js');
|
|
14
14
|
|
|
@@ -25,8 +25,8 @@ var RemoteHttpInterceptor = class extends _chunkAA4NWHDYjs.BatchInterceptor {
|
|
|
25
25
|
super({
|
|
26
26
|
name: "remote-interceptor",
|
|
27
27
|
interceptors: [
|
|
28
|
-
new (0,
|
|
29
|
-
new (0,
|
|
28
|
+
new (0, _chunkEORE2RV6js.ClientRequestInterceptor)(),
|
|
29
|
+
new (0, _chunk5OKLCEIPjs.XMLHttpRequestInterceptor)()
|
|
30
30
|
]
|
|
31
31
|
});
|
|
32
32
|
}
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
} from "./chunk-LNYHQTKT.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ClientRequestInterceptor
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-OVITJLTK.mjs";
|
|
7
7
|
import {
|
|
8
8
|
XMLHttpRequestInterceptor
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-V3QPQ45S.mjs";
|
|
10
10
|
import "./chunk-7II4SWKS.mjs";
|
|
11
|
-
import "./chunk-
|
|
11
|
+
import "./chunk-5XLKQVVL.mjs";
|
|
12
12
|
import "./chunk-MXSWCQAT.mjs";
|
|
13
13
|
import "./chunk-GFH37L5D.mjs";
|
|
14
14
|
import {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
var _chunk3LFH2WCFjs = require('./chunk-3LFH2WCF.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _chunkTSYVWURFjs = require('./chunk-TSYVWURF.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
var _chunkVQ4DZOBBjs = require('./chunk-VQ4DZOBB.js');
|
|
@@ -207,9 +207,7 @@ function parseJson(data) {
|
|
|
207
207
|
|
|
208
208
|
// src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
|
209
209
|
function createResponse(request, body) {
|
|
210
|
-
const responseBodyOrNull =
|
|
211
|
-
request.status
|
|
212
|
-
) ? null : body;
|
|
210
|
+
const responseBodyOrNull = _chunkTSYVWURFjs.isResponseWithoutBody.call(void 0, request.status) ? null : body;
|
|
213
211
|
return new Response(responseBodyOrNull, {
|
|
214
212
|
status: request.status,
|
|
215
213
|
statusText: request.statusText,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/utils/responseUtils.ts
|
|
2
|
+
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
3
|
+
101,
|
|
4
|
+
103,
|
|
5
|
+
204,
|
|
6
|
+
205,
|
|
7
|
+
304
|
|
8
|
+
]);
|
|
9
|
+
function isResponseWithoutBody(status) {
|
|
10
|
+
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
isResponseWithoutBody
|
|
15
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkTSYVWURFjs = require('./chunk-TSYVWURF.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk35HEWOG7js = require('./chunk-35HEWOG7.js');
|
|
@@ -109,9 +109,7 @@ function inheritProperties(source, target) {
|
|
|
109
109
|
|
|
110
110
|
// src/interceptors/ClientRequest/utils/createResponse.ts
|
|
111
111
|
function createResponse(message) {
|
|
112
|
-
const responseBodyOrNull =
|
|
113
|
-
message.statusCode || 200
|
|
114
|
-
) ? null : new ReadableStream({
|
|
112
|
+
const responseBodyOrNull = _chunkTSYVWURFjs.isResponseWithoutBody.call(void 0, message.statusCode || 200) ? null : new ReadableStream({
|
|
115
113
|
start(controller) {
|
|
116
114
|
message.on("data", (chunk) => controller.enqueue(chunk));
|
|
117
115
|
message.on("end", () => controller.close());
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
isResponseWithoutBody
|
|
3
|
+
} from "./chunk-5XLKQVVL.mjs";
|
|
4
4
|
import {
|
|
5
5
|
isPropertyAccessible
|
|
6
6
|
} from "./chunk-MXSWCQAT.mjs";
|
|
@@ -109,9 +109,7 @@ function inheritProperties(source, target) {
|
|
|
109
109
|
|
|
110
110
|
// src/interceptors/ClientRequest/utils/createResponse.ts
|
|
111
111
|
function createResponse(message) {
|
|
112
|
-
const responseBodyOrNull =
|
|
113
|
-
message.statusCode || 200
|
|
114
|
-
) ? null : new ReadableStream({
|
|
112
|
+
const responseBodyOrNull = isResponseWithoutBody(message.statusCode || 200) ? null : new ReadableStream({
|
|
115
113
|
start(controller) {
|
|
116
114
|
message.on("data", (chunk) => controller.enqueue(chunk));
|
|
117
115
|
message.on("end", () => controller.close());
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utils/responseUtils.ts
|
|
2
|
+
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
3
|
+
101,
|
|
4
|
+
103,
|
|
5
|
+
204,
|
|
6
|
+
205,
|
|
7
|
+
304
|
|
8
|
+
]);
|
|
9
|
+
function isResponseWithoutBody(status) {
|
|
10
|
+
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
exports.isResponseWithoutBody = isResponseWithoutBody;
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
toArrayBuffer
|
|
5
5
|
} from "./chunk-7II4SWKS.mjs";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
isResponseWithoutBody
|
|
8
|
+
} from "./chunk-5XLKQVVL.mjs";
|
|
9
9
|
import {
|
|
10
10
|
IS_PATCHED_MODULE
|
|
11
11
|
} from "./chunk-GFH37L5D.mjs";
|
|
@@ -207,9 +207,7 @@ function parseJson(data) {
|
|
|
207
207
|
|
|
208
208
|
// src/interceptors/XMLHttpRequest/utils/createResponse.ts
|
|
209
209
|
function createResponse(request, body) {
|
|
210
|
-
const responseBodyOrNull =
|
|
211
|
-
request.status
|
|
212
|
-
) ? null : body;
|
|
210
|
+
const responseBodyOrNull = isResponseWithoutBody(request.status) ? null : body;
|
|
213
211
|
return new Response(responseBodyOrNull, {
|
|
214
212
|
status: request.status,
|
|
215
213
|
statusText: request.statusText,
|
package/lib/node/index.d.ts
CHANGED
|
@@ -12,4 +12,10 @@ declare function getCleanUrl(url: URL, isAbsolute?: boolean): string;
|
|
|
12
12
|
declare function encodeBuffer(text: string): Uint8Array;
|
|
13
13
|
declare function decodeBuffer(buffer: ArrayBuffer, encoding?: string): string;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Returns a boolean indicating whether the given response status
|
|
17
|
+
* code represents a response that cannot have a body.
|
|
18
|
+
*/
|
|
19
|
+
declare function isResponseWithoutBody(status: number): boolean;
|
|
20
|
+
|
|
21
|
+
export { decodeBuffer, encodeBuffer, getCleanUrl, isResponseWithoutBody };
|
package/lib/node/index.js
CHANGED
|
@@ -7,6 +7,9 @@ var _chunkAA4NWHDYjs = require('./chunk-AA4NWHDY.js');
|
|
|
7
7
|
var _chunk3LFH2WCFjs = require('./chunk-3LFH2WCF.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
var _chunkTSYVWURFjs = require('./chunk-TSYVWURF.js');
|
|
11
|
+
|
|
12
|
+
|
|
10
13
|
var _chunkVQ4DZOBBjs = require('./chunk-VQ4DZOBB.js');
|
|
11
14
|
|
|
12
15
|
|
|
@@ -29,4 +32,5 @@ function getCleanUrl(url, isAbsolute = true) {
|
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
|
|
32
|
-
|
|
35
|
+
|
|
36
|
+
exports.BatchInterceptor = _chunkAA4NWHDYjs.BatchInterceptor; exports.IS_PATCHED_MODULE = _chunkVQ4DZOBBjs.IS_PATCHED_MODULE; exports.Interceptor = _chunkUZM2Y7WJjs.Interceptor; exports.InterceptorReadyState = _chunkUZM2Y7WJjs.InterceptorReadyState; exports.decodeBuffer = _chunk3LFH2WCFjs.decodeBuffer; exports.deleteGlobalSymbol = _chunkUZM2Y7WJjs.deleteGlobalSymbol; exports.encodeBuffer = _chunk3LFH2WCFjs.encodeBuffer; exports.getCleanUrl = getCleanUrl; exports.getGlobalSymbol = _chunkUZM2Y7WJjs.getGlobalSymbol; exports.isResponseWithoutBody = _chunkTSYVWURFjs.isResponseWithoutBody;
|
package/lib/node/index.mjs
CHANGED
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
decodeBuffer,
|
|
6
6
|
encodeBuffer
|
|
7
7
|
} from "./chunk-7II4SWKS.mjs";
|
|
8
|
+
import {
|
|
9
|
+
isResponseWithoutBody
|
|
10
|
+
} from "./chunk-5XLKQVVL.mjs";
|
|
8
11
|
import {
|
|
9
12
|
IS_PATCHED_MODULE
|
|
10
13
|
} from "./chunk-GFH37L5D.mjs";
|
|
@@ -28,5 +31,6 @@ export {
|
|
|
28
31
|
deleteGlobalSymbol,
|
|
29
32
|
encodeBuffer,
|
|
30
33
|
getCleanUrl,
|
|
31
|
-
getGlobalSymbol
|
|
34
|
+
getGlobalSymbol,
|
|
35
|
+
isResponseWithoutBody
|
|
32
36
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../../chunk-
|
|
3
|
+
var _chunkEORE2RV6js = require('../../chunk-EORE2RV6.js');
|
|
4
|
+
require('../../chunk-TSYVWURF.js');
|
|
5
5
|
require('../../chunk-35HEWOG7.js');
|
|
6
6
|
require('../../chunk-5PTPJLB7.js');
|
|
7
7
|
require('../../chunk-UZM2Y7WJ.js');
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
exports.ClientRequestInterceptor =
|
|
10
|
+
exports.ClientRequestInterceptor = _chunkEORE2RV6js.ClientRequestInterceptor;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
4
|
-
import "../../chunk-
|
|
3
|
+
} from "../../chunk-OVITJLTK.mjs";
|
|
4
|
+
import "../../chunk-5XLKQVVL.mjs";
|
|
5
5
|
import "../../chunk-MXSWCQAT.mjs";
|
|
6
6
|
import "../../chunk-YQGTMMOZ.mjs";
|
|
7
7
|
import "../../chunk-JAW6F2FR.mjs";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunk5OKLCEIPjs = require('../../chunk-5OKLCEIP.js');
|
|
4
4
|
require('../../chunk-3LFH2WCF.js');
|
|
5
|
-
require('../../chunk-
|
|
5
|
+
require('../../chunk-TSYVWURF.js');
|
|
6
6
|
require('../../chunk-VQ4DZOBB.js');
|
|
7
7
|
require('../../chunk-5PTPJLB7.js');
|
|
8
8
|
require('../../chunk-UZM2Y7WJ.js');
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.XMLHttpRequestInterceptor =
|
|
11
|
+
exports.XMLHttpRequestInterceptor = _chunk5OKLCEIPjs.XMLHttpRequestInterceptor;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
XMLHttpRequestInterceptor
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-V3QPQ45S.mjs";
|
|
4
4
|
import "../../chunk-7II4SWKS.mjs";
|
|
5
|
-
import "../../chunk-
|
|
5
|
+
import "../../chunk-5XLKQVVL.mjs";
|
|
6
6
|
import "../../chunk-GFH37L5D.mjs";
|
|
7
7
|
import "../../chunk-YQGTMMOZ.mjs";
|
|
8
8
|
import "../../chunk-JAW6F2FR.mjs";
|
package/lib/node/presets/node.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkEORE2RV6js = require('../chunk-EORE2RV6.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk5OKLCEIPjs = require('../chunk-5OKLCEIP.js');
|
|
7
7
|
require('../chunk-3LFH2WCF.js');
|
|
8
|
-
require('../chunk-
|
|
8
|
+
require('../chunk-TSYVWURF.js');
|
|
9
9
|
require('../chunk-35HEWOG7.js');
|
|
10
10
|
require('../chunk-VQ4DZOBB.js');
|
|
11
11
|
require('../chunk-5PTPJLB7.js');
|
|
@@ -13,8 +13,8 @@ require('../chunk-UZM2Y7WJ.js');
|
|
|
13
13
|
|
|
14
14
|
// src/presets/node.ts
|
|
15
15
|
var node_default = [
|
|
16
|
-
new (0,
|
|
17
|
-
new (0,
|
|
16
|
+
new (0, _chunkEORE2RV6js.ClientRequestInterceptor)(),
|
|
17
|
+
new (0, _chunk5OKLCEIPjs.XMLHttpRequestInterceptor)()
|
|
18
18
|
];
|
|
19
19
|
|
|
20
20
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientRequestInterceptor
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-OVITJLTK.mjs";
|
|
4
4
|
import {
|
|
5
5
|
XMLHttpRequestInterceptor
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-V3QPQ45S.mjs";
|
|
7
7
|
import "../chunk-7II4SWKS.mjs";
|
|
8
|
-
import "../chunk-
|
|
8
|
+
import "../chunk-5XLKQVVL.mjs";
|
|
9
9
|
import "../chunk-MXSWCQAT.mjs";
|
|
10
10
|
import "../chunk-GFH37L5D.mjs";
|
|
11
11
|
import "../chunk-YQGTMMOZ.mjs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mswjs/interceptors",
|
|
3
3
|
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.",
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.13",
|
|
5
5
|
"main": "./lib/node/index.js",
|
|
6
6
|
"module": "./lib/node/index.mjs",
|
|
7
7
|
"types": "./lib/node/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { it, expect } from 'vitest'
|
|
|
2
2
|
import { Socket } from 'net'
|
|
3
3
|
import * as http from 'http'
|
|
4
4
|
import { createResponse } from './createResponse'
|
|
5
|
-
import {
|
|
5
|
+
import { RESPONSE_STATUS_CODES_WITHOUT_BODY } from '../../../utils/responseUtils'
|
|
6
6
|
|
|
7
7
|
it('creates a fetch api response from http incoming message', async () => {
|
|
8
8
|
const message = new http.IncomingMessage(new Socket())
|
|
@@ -22,7 +22,15 @@ it('creates a fetch api response from http incoming message', async () => {
|
|
|
22
22
|
expect(await response.json()).toEqual({ firstName: 'John' })
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @note Ignore 1xx response status code because those cannot
|
|
27
|
+
* be used as the init to the "Response" constructor.
|
|
28
|
+
*/
|
|
29
|
+
const CONSTRUCTABLE_RESPONSE_STATUS_CODES = Array.from(
|
|
30
|
+
RESPONSE_STATUS_CODES_WITHOUT_BODY
|
|
31
|
+
).filter((status) => status >= 200)
|
|
32
|
+
|
|
33
|
+
it.each(CONSTRUCTABLE_RESPONSE_STATUS_CODES)(
|
|
26
34
|
'ignores message body for %i response status',
|
|
27
35
|
(responseStatus) => {
|
|
28
36
|
const message = new http.IncomingMessage(new Socket())
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type { IncomingHttpHeaders, IncomingMessage } from 'http'
|
|
2
|
-
import {
|
|
2
|
+
import { isResponseWithoutBody } from '../../../utils/responseUtils'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Creates a Fetch API `Response` instance from the given
|
|
6
6
|
* `http.IncomingMessage` instance.
|
|
7
7
|
*/
|
|
8
8
|
export function createResponse(message: IncomingMessage): Response {
|
|
9
|
-
const responseBodyOrNull =
|
|
10
|
-
message.statusCode || 200
|
|
11
|
-
)
|
|
9
|
+
const responseBodyOrNull = isResponseWithoutBody(message.statusCode || 200)
|
|
12
10
|
? null
|
|
13
11
|
: new ReadableStream({
|
|
14
12
|
start(controller) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isResponseWithoutBody } from '../../../utils/responseUtils'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Creates a Fetch API `Response` instance from the given
|
|
@@ -16,11 +16,7 @@ export function createResponse(
|
|
|
16
16
|
* when constructing a Response instance.
|
|
17
17
|
* @see https://github.com/mswjs/interceptors/issues/379
|
|
18
18
|
*/
|
|
19
|
-
const responseBodyOrNull =
|
|
20
|
-
request.status
|
|
21
|
-
)
|
|
22
|
-
? null
|
|
23
|
-
: body
|
|
19
|
+
const responseBodyOrNull = isResponseWithoutBody(request.status) ? null : body
|
|
24
20
|
|
|
25
21
|
return new Response(responseBodyOrNull, {
|
|
26
22
|
status: request.status,
|
|
@@ -2,4 +2,14 @@
|
|
|
2
2
|
* Response status codes for responses that cannot have body.
|
|
3
3
|
* @see https://fetch.spec.whatwg.org/#statuses
|
|
4
4
|
*/
|
|
5
|
-
export const
|
|
5
|
+
export const RESPONSE_STATUS_CODES_WITHOUT_BODY = new Set([
|
|
6
|
+
101, 103, 204, 205, 304,
|
|
7
|
+
])
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns a boolean indicating whether the given response status
|
|
11
|
+
* code represents a response that cannot have a body.
|
|
12
|
+
*/
|
|
13
|
+
export function isResponseWithoutBody(status: number): boolean {
|
|
14
|
+
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status)
|
|
15
|
+
}
|