@mswjs/interceptors 0.20.0 → 0.21.1
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/README.md +7 -7
- package/lib/browser/Interceptor-959f650e.d.ts +104 -0
- package/lib/browser/chunk-5B525MKF.mjs +2139 -0
- package/lib/browser/chunk-BQYA7ER5.mjs +258 -0
- package/lib/browser/chunk-IIY3SHU3.js +2139 -0
- package/lib/browser/chunk-QWL3EOEY.js +258 -0
- package/lib/browser/chunk-STA6QBYM.mjs +64 -0
- package/lib/browser/chunk-ZJOF5MEZ.js +64 -0
- package/lib/browser/index.d.ts +31 -0
- package/lib/browser/index.js +51 -0
- package/lib/browser/index.mjs +51 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.d.ts +14 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.js +657 -0
- package/lib/browser/interceptors/XMLHttpRequest/index.mjs +657 -0
- package/lib/browser/interceptors/fetch/index.d.ts +12 -0
- package/lib/browser/interceptors/fetch/index.js +94 -0
- package/lib/browser/interceptors/fetch/index.mjs +94 -0
- package/lib/node/BatchInterceptor-a7261b26.d.ts +21 -0
- package/lib/node/Interceptor-997045eb.d.ts +104 -0
- package/lib/{RemoteHttpInterceptor.d.ts → node/RemoteHttpInterceptor.d.ts} +17 -12
- package/lib/node/RemoteHttpInterceptor.js +176 -0
- package/lib/node/RemoteHttpInterceptor.mjs +176 -0
- package/lib/node/chunk-6GWWOJ23.js +29 -0
- package/lib/node/chunk-6V3JXLBF.js +6093 -0
- package/lib/node/chunk-CIN5URNI.mjs +29 -0
- package/lib/node/chunk-GFH37L5D.mjs +6 -0
- package/lib/node/chunk-HDUJCCWF.js +661 -0
- package/lib/node/chunk-JISWS3Y3.mjs +31 -0
- package/lib/node/chunk-KZJG2UW7.js +31 -0
- package/lib/node/chunk-NNVTJLQA.mjs +6093 -0
- package/lib/node/chunk-QMIXLBOU.js +291 -0
- package/lib/node/chunk-STA6QBYM.mjs +64 -0
- package/lib/node/chunk-UVNTVJHD.js +667 -0
- package/lib/node/chunk-VQ4DZOBB.js +6 -0
- package/lib/node/chunk-Z5JAVEOB.mjs +667 -0
- package/lib/node/chunk-ZJOF5MEZ.js +64 -0
- package/lib/node/chunk-ZSI7MX3V.mjs +291 -0
- package/lib/node/chunk-ZWCZGO3W.mjs +661 -0
- package/lib/node/index.d.ts +14 -0
- package/lib/node/index.js +32 -0
- package/lib/node/index.mjs +32 -0
- package/lib/node/interceptors/ClientRequest/index.d.ts +22 -0
- package/lib/node/interceptors/ClientRequest/index.js +9 -0
- package/lib/node/interceptors/ClientRequest/index.mjs +9 -0
- package/lib/node/interceptors/XMLHttpRequest/index.d.ts +14 -0
- package/lib/node/interceptors/XMLHttpRequest/index.js +11 -0
- package/lib/node/interceptors/XMLHttpRequest/index.mjs +11 -0
- package/lib/node/interceptors/fetch/index.d.ts +12 -0
- package/lib/node/interceptors/fetch/index.js +96 -0
- package/lib/node/interceptors/fetch/index.mjs +96 -0
- package/package.json +63 -10
- package/src/interceptors/ClientRequest/NodeClientRequest.test.ts +1 -1
- package/src/interceptors/ClientRequest/NodeClientRequest.ts +26 -16
- package/src/interceptors/ClientRequest/utils/normalizeClientRequestArgs.ts +1 -1
- package/src/shims/webEncoding.ts +9 -0
- package/src/utils/bufferUtils.ts +1 -1
- package/lib/BatchInterceptor.d.ts +0 -18
- package/lib/BatchInterceptor.js +0 -34
- package/lib/BatchInterceptor.js.map +0 -1
- package/lib/Interceptor.d.ts +0 -50
- package/lib/Interceptor.js +0 -172
- package/lib/Interceptor.js.map +0 -1
- package/lib/RemoteHttpInterceptor.js +0 -158
- package/lib/RemoteHttpInterceptor.js.map +0 -1
- package/lib/glossary.d.ts +0 -7
- package/lib/glossary.js +0 -5
- package/lib/glossary.js.map +0 -1
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -23
- package/lib/index.js.map +0 -1
- package/lib/interceptors/ClientRequest/NodeClientRequest.d.ts +0 -46
- package/lib/interceptors/ClientRequest/NodeClientRequest.js +0 -325
- package/lib/interceptors/ClientRequest/NodeClientRequest.js.map +0 -1
- package/lib/interceptors/ClientRequest/http.get.d.ts +0 -4
- package/lib/interceptors/ClientRequest/http.get.js +0 -19
- package/lib/interceptors/ClientRequest/http.get.js.map +0 -1
- package/lib/interceptors/ClientRequest/http.request.d.ts +0 -4
- package/lib/interceptors/ClientRequest/http.request.js +0 -16
- package/lib/interceptors/ClientRequest/http.request.js.map +0 -1
- package/lib/interceptors/ClientRequest/index.d.ts +0 -19
- package/lib/interceptors/ClientRequest/index.js +0 -50
- package/lib/interceptors/ClientRequest/index.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.d.ts +0 -10
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js +0 -60
- package/lib/interceptors/ClientRequest/utils/cloneIncomingMessage.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/createRequest.d.ts +0 -6
- package/lib/interceptors/ClientRequest/utils/createRequest.js +0 -30
- package/lib/interceptors/ClientRequest/utils/createRequest.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/createResponse.d.ts +0 -8
- package/lib/interceptors/ClientRequest/utils/createResponse.js +0 -24
- package/lib/interceptors/ClientRequest/utils/createResponse.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.d.ts +0 -3
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js +0 -57
- package/lib/interceptors/ClientRequest/utils/getIncomingMessageBody.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.d.ts +0 -17
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js +0 -151
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestArgs.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.d.ts +0 -15
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js +0 -33
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestEndArgs.js.map +0 -1
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.d.ts +0 -13
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js +0 -20
- package/lib/interceptors/ClientRequest/utils/normalizeClientRequestWriteArgs.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.d.ts +0 -44
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js +0 -413
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestController.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.d.ts +0 -20
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js +0 -75
- package/lib/interceptors/XMLHttpRequest/XMLHttpRequestProxy.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/index.d.ts +0 -12
- package/lib/interceptors/XMLHttpRequest/index.js +0 -41
- package/lib/interceptors/XMLHttpRequest/index.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.d.ts +0 -31
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js +0 -44
- package/lib/interceptors/XMLHttpRequest/polyfills/EventPolyfill.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.d.ts +0 -8
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js +0 -15
- package/lib/interceptors/XMLHttpRequest/polyfills/ProgressEventPolyfill.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.d.ts +0 -4
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js +0 -14
- package/lib/interceptors/XMLHttpRequest/utils/concatArrayBuffer.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.d.ts +0 -2
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js +0 -37
- package/lib/interceptors/XMLHttpRequest/utils/createEvent.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.d.ts +0 -2
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js +0 -14
- package/lib/interceptors/XMLHttpRequest/utils/createResponse.js.map +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.d.ts +0 -1
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js +0 -17
- package/lib/interceptors/XMLHttpRequest/utils/isDomParserSupportedType.js.map +0 -1
- package/lib/interceptors/fetch/index.d.ts +0 -8
- package/lib/interceptors/fetch/index.js +0 -81
- package/lib/interceptors/fetch/index.js.map +0 -1
- package/lib/presets/browser.d.ts +0 -8
- package/lib/presets/browser.js +0 -10
- package/lib/presets/browser.js.map +0 -1
- package/lib/presets/node.d.ts +0 -8
- package/lib/presets/node.js +0 -10
- package/lib/presets/node.js.map +0 -1
- package/lib/utils/AsyncEventEmitter.d.ts +0 -33
- package/lib/utils/AsyncEventEmitter.js +0 -148
- package/lib/utils/AsyncEventEmitter.js.map +0 -1
- package/lib/utils/bufferUtils.d.ts +0 -8
- package/lib/utils/bufferUtils.js +0 -24
- package/lib/utils/bufferUtils.js.map +0 -1
- package/lib/utils/cloneObject.d.ts +0 -1
- package/lib/utils/cloneObject.js +0 -28
- package/lib/utils/cloneObject.js.map +0 -1
- package/lib/utils/createLazyCallback.d.ts +0 -11
- package/lib/utils/createLazyCallback.js +0 -40
- package/lib/utils/createLazyCallback.js.map +0 -1
- package/lib/utils/createProxy.d.ts +0 -8
- package/lib/utils/createProxy.js +0 -45
- package/lib/utils/createProxy.js.map +0 -1
- package/lib/utils/getCleanUrl.d.ts +0 -4
- package/lib/utils/getCleanUrl.js +0 -11
- package/lib/utils/getCleanUrl.js.map +0 -1
- package/lib/utils/getRequestOptionsByUrl.d.ts +0 -8
- package/lib/utils/getRequestOptionsByUrl.js +0 -28
- package/lib/utils/getRequestOptionsByUrl.js.map +0 -1
- package/lib/utils/getUrlByRequestOptions.d.ts +0 -11
- package/lib/utils/getUrlByRequestOptions.js +0 -78
- package/lib/utils/getUrlByRequestOptions.js.map +0 -1
- package/lib/utils/isObject.d.ts +0 -4
- package/lib/utils/isObject.js +0 -11
- package/lib/utils/isObject.js.map +0 -1
- package/lib/utils/nextTick.d.ts +0 -2
- package/lib/utils/nextTick.js +0 -16
- package/lib/utils/nextTick.js.map +0 -1
- package/lib/utils/parseJson.d.ts +0 -5
- package/lib/utils/parseJson.js +0 -18
- package/lib/utils/parseJson.js.map +0 -1
- package/lib/utils/toInteractiveRequest.d.ts +0 -7
- package/lib/utils/toInteractiveRequest.js +0 -20
- package/lib/utils/toInteractiveRequest.js.map +0 -1
- package/lib/utils/uuid.d.ts +0 -1
- package/lib/utils/uuid.js +0 -12
- package/lib/utils/uuid.js.map +0 -1
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.NodeClientRequest = void 0;
|
|
13
|
-
const http_1 = require("http");
|
|
14
|
-
const until_1 = require("@open-draft/until");
|
|
15
|
-
const normalizeClientRequestEndArgs_1 = require("./utils/normalizeClientRequestEndArgs");
|
|
16
|
-
const normalizeClientRequestWriteArgs_1 = require("./utils/normalizeClientRequestWriteArgs");
|
|
17
|
-
const cloneIncomingMessage_1 = require("./utils/cloneIncomingMessage");
|
|
18
|
-
const createResponse_1 = require("./utils/createResponse");
|
|
19
|
-
const createRequest_1 = require("./utils/createRequest");
|
|
20
|
-
const toInteractiveRequest_1 = require("../../utils/toInteractiveRequest");
|
|
21
|
-
const uuid_1 = require("../../utils/uuid");
|
|
22
|
-
class NodeClientRequest extends http_1.ClientRequest {
|
|
23
|
-
constructor([url, requestOptions, callback], options) {
|
|
24
|
-
super(requestOptions, callback);
|
|
25
|
-
this.chunks = [];
|
|
26
|
-
this.responseSource = 'mock';
|
|
27
|
-
this.log = options.log.extend(`request ${requestOptions.method} ${url.href}`);
|
|
28
|
-
this.log('constructing ClientRequest using options:', {
|
|
29
|
-
url,
|
|
30
|
-
requestOptions,
|
|
31
|
-
callback,
|
|
32
|
-
});
|
|
33
|
-
this.url = url;
|
|
34
|
-
this.emitter = options.emitter;
|
|
35
|
-
// Set request buffer to null by default so that GET/HEAD requests
|
|
36
|
-
// without a body wouldn't suddenly get one.
|
|
37
|
-
this.requestBuffer = null;
|
|
38
|
-
// Construct a mocked response message.
|
|
39
|
-
this.response = new http_1.IncomingMessage(this.socket);
|
|
40
|
-
}
|
|
41
|
-
writeRequestBodyChunk(chunk, encoding) {
|
|
42
|
-
if (chunk == null) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
if (this.requestBuffer == null) {
|
|
46
|
-
this.requestBuffer = Buffer.from([]);
|
|
47
|
-
}
|
|
48
|
-
const resolvedChunk = Buffer.isBuffer(chunk)
|
|
49
|
-
? chunk
|
|
50
|
-
: Buffer.from(chunk, encoding);
|
|
51
|
-
this.requestBuffer = Buffer.concat([this.requestBuffer, resolvedChunk]);
|
|
52
|
-
}
|
|
53
|
-
write(...args) {
|
|
54
|
-
var _a;
|
|
55
|
-
const [chunk, encoding, callback] = (0, normalizeClientRequestWriteArgs_1.normalizeClientRequestWriteArgs)(args);
|
|
56
|
-
this.log('write:', { chunk, encoding, callback });
|
|
57
|
-
this.chunks.push({ chunk, encoding });
|
|
58
|
-
// Write each request body chunk to the internal buffer.
|
|
59
|
-
this.writeRequestBodyChunk(chunk, encoding);
|
|
60
|
-
this.log('chunk successfully stored!', (_a = this.requestBuffer) === null || _a === void 0 ? void 0 : _a.byteLength);
|
|
61
|
-
/**
|
|
62
|
-
* Prevent invoking the callback if the written chunk is empty.
|
|
63
|
-
* @see https://nodejs.org/api/http.html#requestwritechunk-encoding-callback
|
|
64
|
-
*/
|
|
65
|
-
if (!chunk || chunk.length === 0) {
|
|
66
|
-
this.log('written chunk is empty, skipping callback...');
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
callback === null || callback === void 0 ? void 0 : callback();
|
|
70
|
-
}
|
|
71
|
-
// Do not write the request body chunks to prevent
|
|
72
|
-
// the Socket from sending data to a potentially existing
|
|
73
|
-
// server when there is a mocked response defined.
|
|
74
|
-
return true;
|
|
75
|
-
}
|
|
76
|
-
end(...args) {
|
|
77
|
-
this.log('end', args);
|
|
78
|
-
const requestId = (0, uuid_1.uuidv4)();
|
|
79
|
-
const [chunk, encoding, callback] = (0, normalizeClientRequestEndArgs_1.normalizeClientRequestEndArgs)(...args);
|
|
80
|
-
this.log('normalized arguments:', { chunk, encoding, callback });
|
|
81
|
-
// Write the last request body chunk passed to the "end()" method.
|
|
82
|
-
this.writeRequestBodyChunk(chunk, encoding || undefined);
|
|
83
|
-
const capturedRequest = (0, createRequest_1.createRequest)(this);
|
|
84
|
-
const interactiveRequest = (0, toInteractiveRequest_1.toInteractiveRequest)(capturedRequest);
|
|
85
|
-
// Prevent handling this request if it has already been handled
|
|
86
|
-
// in another (parent) interceptor (like XMLHttpRequest -> ClientRequest).
|
|
87
|
-
// That means some interceptor up the chain has concluded that
|
|
88
|
-
// this request must be performed as-is.
|
|
89
|
-
if (this.getHeader('X-Request-Id') != null) {
|
|
90
|
-
this.removeHeader('X-Request-Id');
|
|
91
|
-
return this.passthrough(chunk, encoding, callback);
|
|
92
|
-
}
|
|
93
|
-
// Notify the interceptor about the request.
|
|
94
|
-
// This will call any "request" listeners the users have.
|
|
95
|
-
this.log('emitting the "request" event for %d listener(s)...', this.emitter.listenerCount('request'));
|
|
96
|
-
this.emitter.emit('request', interactiveRequest, requestId);
|
|
97
|
-
// Execute the resolver Promise like a side-effect.
|
|
98
|
-
// Node.js 16 forces "ClientRequest.end" to be synchronous and return "this".
|
|
99
|
-
(0, until_1.until)(() => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
yield this.emitter.untilIdle('request', ({ args: [, pendingRequestId] }) => {
|
|
101
|
-
/**
|
|
102
|
-
* @note Await only those listeners that are relevant to this request.
|
|
103
|
-
* This prevents extraneous parallel request from blocking the resolution
|
|
104
|
-
* of another, unrelated request. For example, during response patching,
|
|
105
|
-
* when request resolution is nested.
|
|
106
|
-
*/
|
|
107
|
-
return pendingRequestId === requestId;
|
|
108
|
-
});
|
|
109
|
-
const [mockedResponse] = yield interactiveRequest.respondWith.invoked();
|
|
110
|
-
this.log('event.respondWith called with:', mockedResponse);
|
|
111
|
-
return mockedResponse;
|
|
112
|
-
})).then(([resolverException, mockedResponse]) => {
|
|
113
|
-
this.log('the listeners promise awaited!');
|
|
114
|
-
// Halt the request whenever the resolver throws an exception.
|
|
115
|
-
if (resolverException) {
|
|
116
|
-
this.log('encountered resolver exception, aborting request...', resolverException);
|
|
117
|
-
this.emit('error', resolverException);
|
|
118
|
-
this.terminate();
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
// Forward any request headers that the "request" listener
|
|
122
|
-
// may have modified before proceeding with this request.
|
|
123
|
-
for (const [headerName, headerValue] of capturedRequest.headers) {
|
|
124
|
-
this.setHeader(headerName, headerValue);
|
|
125
|
-
}
|
|
126
|
-
if (mockedResponse) {
|
|
127
|
-
const responseClone = mockedResponse.clone();
|
|
128
|
-
this.log('received mocked response:', mockedResponse);
|
|
129
|
-
this.responseSource = 'mock';
|
|
130
|
-
this.respondWith(mockedResponse);
|
|
131
|
-
this.log(mockedResponse.status, mockedResponse.statusText, '(MOCKED)');
|
|
132
|
-
callback === null || callback === void 0 ? void 0 : callback();
|
|
133
|
-
this.log('emitting the custom "response" event...');
|
|
134
|
-
this.emitter.emit('response', responseClone, capturedRequest, requestId);
|
|
135
|
-
this.log('request (mock) is completed');
|
|
136
|
-
return this;
|
|
137
|
-
}
|
|
138
|
-
this.log('no mocked response received!');
|
|
139
|
-
this.once('response-internal', (message) => {
|
|
140
|
-
this.log(message.statusCode, message.statusMessage);
|
|
141
|
-
this.log('original response headers:', message.headers);
|
|
142
|
-
this.log('emitting the custom "response" event...');
|
|
143
|
-
this.emitter.emit('response', (0, createResponse_1.createResponse)(message), capturedRequest, requestId);
|
|
144
|
-
});
|
|
145
|
-
return this.passthrough(chunk, encoding, callback);
|
|
146
|
-
});
|
|
147
|
-
return this;
|
|
148
|
-
}
|
|
149
|
-
emit(event, ...data) {
|
|
150
|
-
this.log('emit: %s', event);
|
|
151
|
-
if (event === 'response') {
|
|
152
|
-
this.log('found "response" event, cloning the response...');
|
|
153
|
-
try {
|
|
154
|
-
/**
|
|
155
|
-
* Clone the response object when emitting the "response" event.
|
|
156
|
-
* This prevents the response body stream from locking
|
|
157
|
-
* and allows reading it twice:
|
|
158
|
-
* 1. Internal "response" event from the observer.
|
|
159
|
-
* 2. Any external response body listeners.
|
|
160
|
-
* @see https://github.com/mswjs/interceptors/issues/161
|
|
161
|
-
*/
|
|
162
|
-
const response = data[0];
|
|
163
|
-
const firstClone = (0, cloneIncomingMessage_1.cloneIncomingMessage)(response);
|
|
164
|
-
const secondClone = (0, cloneIncomingMessage_1.cloneIncomingMessage)(response);
|
|
165
|
-
this.emit('response-internal', secondClone);
|
|
166
|
-
this.log('response successfully cloned, emitting "response" event...');
|
|
167
|
-
return super.emit(event, firstClone, ...data.slice(1));
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
this.log('error when cloning response:', error);
|
|
171
|
-
return super.emit(event, ...data);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (event === 'error') {
|
|
175
|
-
const error = data[0];
|
|
176
|
-
const errorCode = error.code || '';
|
|
177
|
-
this.log('error:\n', error);
|
|
178
|
-
// Suppress certain errors while using the "mock" source.
|
|
179
|
-
// For example, no need to destroy this request if it connects
|
|
180
|
-
// to a non-existing hostname but has a mocked response.
|
|
181
|
-
if (this.responseSource === 'mock' &&
|
|
182
|
-
NodeClientRequest.suppressErrorCodes.includes(errorCode)) {
|
|
183
|
-
// Capture the first emitted error in order to replay
|
|
184
|
-
// it later if this request won't have any mocked response.
|
|
185
|
-
if (!this.capturedError) {
|
|
186
|
-
this.capturedError = error;
|
|
187
|
-
this.log('captured the first error:', this.capturedError);
|
|
188
|
-
}
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return super.emit(event, ...data);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Performs the intercepted request as-is.
|
|
196
|
-
* Replays the captured request body chunks,
|
|
197
|
-
* still emits the internal events, and wraps
|
|
198
|
-
* up the request with `super.end()`.
|
|
199
|
-
*/
|
|
200
|
-
passthrough(chunk, encoding, callback) {
|
|
201
|
-
// Set the response source to "bypass".
|
|
202
|
-
// Any errors emitted past this point are not suppressed.
|
|
203
|
-
this.responseSource = 'bypass';
|
|
204
|
-
// Propagate previously captured errors.
|
|
205
|
-
// For example, a ECONNREFUSED error when connecting to a non-existing host.
|
|
206
|
-
if (this.capturedError) {
|
|
207
|
-
this.emit('error', this.capturedError);
|
|
208
|
-
return this;
|
|
209
|
-
}
|
|
210
|
-
this.log('writing request chunks...', this.chunks);
|
|
211
|
-
// Write the request body chunks in the order of ".write()" calls.
|
|
212
|
-
// Note that no request body has been written prior to this point
|
|
213
|
-
// in order to prevent the Socket to communicate with a potentially
|
|
214
|
-
// existing server.
|
|
215
|
-
for (const { chunk, encoding } of this.chunks) {
|
|
216
|
-
if (encoding) {
|
|
217
|
-
super.write(chunk, encoding);
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
super.write(chunk);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
this.once('error', (error) => {
|
|
224
|
-
this.log('original request error:', error);
|
|
225
|
-
});
|
|
226
|
-
this.once('abort', () => {
|
|
227
|
-
this.log('original request aborted!');
|
|
228
|
-
});
|
|
229
|
-
this.once('response-internal', (message) => {
|
|
230
|
-
this.log(message.statusCode, message.statusMessage);
|
|
231
|
-
this.log('original response headers:', message.headers);
|
|
232
|
-
});
|
|
233
|
-
this.log('performing original request...');
|
|
234
|
-
// This call signature is way too dynamic.
|
|
235
|
-
return super.end(...[chunk, encoding, callback].filter(Boolean));
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Responds to this request instance using a mocked response.
|
|
239
|
-
*/
|
|
240
|
-
respondWith(mockedResponse) {
|
|
241
|
-
this.log('responding with a mocked response...', mockedResponse);
|
|
242
|
-
const { status, statusText, headers, body } = mockedResponse;
|
|
243
|
-
this.response.statusCode = status;
|
|
244
|
-
this.response.statusMessage = statusText;
|
|
245
|
-
if (headers) {
|
|
246
|
-
this.response.headers = {};
|
|
247
|
-
headers.forEach((headerValue, headerName) => {
|
|
248
|
-
/**
|
|
249
|
-
* @note Make sure that multi-value headers are appended correctly.
|
|
250
|
-
*/
|
|
251
|
-
this.response.rawHeaders.push(headerName, headerValue);
|
|
252
|
-
const insensitiveHeaderName = headerName.toLowerCase();
|
|
253
|
-
const prevHeaders = this.response.headers[insensitiveHeaderName];
|
|
254
|
-
this.response.headers[insensitiveHeaderName] = prevHeaders
|
|
255
|
-
? Array.prototype.concat([], prevHeaders, headerValue)
|
|
256
|
-
: headerValue;
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
this.log('mocked response headers ready:', headers);
|
|
260
|
-
const closeResponseStream = () => {
|
|
261
|
-
// Push "null" to indicate that the response body is complete
|
|
262
|
-
// and shouldn't be written to anymore.
|
|
263
|
-
this.response.push(null);
|
|
264
|
-
this.response.complete = true;
|
|
265
|
-
};
|
|
266
|
-
if (body) {
|
|
267
|
-
const bodyReader = body.getReader();
|
|
268
|
-
const readNextChunk = () => __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
const { done, value } = yield bodyReader.read();
|
|
270
|
-
if (done) {
|
|
271
|
-
closeResponseStream();
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
// this.response.push(Buffer.from(body))
|
|
275
|
-
this.response.push(value);
|
|
276
|
-
return readNextChunk();
|
|
277
|
-
});
|
|
278
|
-
readNextChunk();
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
closeResponseStream();
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Set the internal "res" property to the mocked "OutgoingMessage"
|
|
285
|
-
* to make the "ClientRequest" instance think there's data received
|
|
286
|
-
* from the socket.
|
|
287
|
-
* @see https://github.com/nodejs/node/blob/9c405f2591f5833d0247ed0fafdcd68c5b14ce7a/lib/_http_client.js#L501
|
|
288
|
-
*/
|
|
289
|
-
// @ts-ignore
|
|
290
|
-
this.res = this.response;
|
|
291
|
-
this.finished = true;
|
|
292
|
-
Object.defineProperty(this, 'writableEnded', {
|
|
293
|
-
value: true,
|
|
294
|
-
});
|
|
295
|
-
this.emit('finish');
|
|
296
|
-
this.emit('response', this.response);
|
|
297
|
-
this.terminate();
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Terminates a pending request.
|
|
301
|
-
*/
|
|
302
|
-
terminate() {
|
|
303
|
-
var _a;
|
|
304
|
-
/**
|
|
305
|
-
* @note Some request clients (e.g. Octokit) create a ClientRequest
|
|
306
|
-
* in a way that it has no Agent set. Now, whether that's correct is
|
|
307
|
-
* debatable, but we should still handle this case gracefully.
|
|
308
|
-
* @see https://github.com/mswjs/interceptors/issues/304
|
|
309
|
-
*/
|
|
310
|
-
// @ts-ignore
|
|
311
|
-
(_a = this.agent) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
exports.NodeClientRequest = NodeClientRequest;
|
|
315
|
-
/**
|
|
316
|
-
* The list of internal Node.js errors to suppress while
|
|
317
|
-
* using the "mock" response source.
|
|
318
|
-
*/
|
|
319
|
-
NodeClientRequest.suppressErrorCodes = [
|
|
320
|
-
'ENOTFOUND',
|
|
321
|
-
'ECONNREFUSED',
|
|
322
|
-
'ECONNRESET',
|
|
323
|
-
'EAI_AGAIN',
|
|
324
|
-
];
|
|
325
|
-
//# sourceMappingURL=NodeClientRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NodeClientRequest.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/NodeClientRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+BAAqD;AACrD,6CAAyC;AAEzC,yFAI8C;AAE9C,6FAGgD;AAChD,uEAAmE;AACnE,2DAAuD;AACvD,yDAAqD;AACrD,2EAAuE;AACvE,2CAAyC;AASzC,MAAa,iBAAkB,SAAQ,oBAAa;IAyBlD,YACE,CAAC,GAAG,EAAE,cAAc,EAAE,QAAQ,CAA8B,EAC5D,OAA0B;QAE1B,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAA;QAdzB,WAAM,GAGT,EAAE,CAAA;QACC,mBAAc,GAAsB,MAAM,CAAA;QAYhD,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,CAC3B,WAAW,cAAc,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,CAC/C,CAAA;QAED,IAAI,CAAC,GAAG,CAAC,2CAA2C,EAAE;YACpD,GAAG;YACH,cAAc;YACd,QAAQ;SACT,CAAC,CAAA;QAEF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAE9B,kEAAkE;QAClE,4CAA4C;QAC5C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QAEzB,uCAAuC;QACvC,IAAI,CAAC,QAAQ,GAAG,IAAI,sBAAe,CA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-
import { ClientRequest } from 'node:http';
|
|
2
|
-
import { NodeClientOptions, Protocol } from './NodeClientRequest';
|
|
3
|
-
import { ClientRequestArgs } from './utils/normalizeClientRequestArgs';
|
|
4
|
-
export declare function get(protocol: Protocol, options: NodeClientOptions): (...args: ClientRequestArgs) => ClientRequest;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.get = void 0;
|
|
4
|
-
const NodeClientRequest_1 = require("./NodeClientRequest");
|
|
5
|
-
const normalizeClientRequestArgs_1 = require("./utils/normalizeClientRequestArgs");
|
|
6
|
-
function get(protocol, options) {
|
|
7
|
-
return (...args) => {
|
|
8
|
-
const clientRequestArgs = (0, normalizeClientRequestArgs_1.normalizeClientRequestArgs)(`${protocol}:`, ...args);
|
|
9
|
-
const request = new NodeClientRequest_1.NodeClientRequest(clientRequestArgs, options);
|
|
10
|
-
/**
|
|
11
|
-
* @note https://nodejs.org/api/http.html#httpgetoptions-callback
|
|
12
|
-
* "http.get" sets the method to "GET" and calls "req.end()" automatically.
|
|
13
|
-
*/
|
|
14
|
-
request.end();
|
|
15
|
-
return request;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
exports.get = get;
|
|
19
|
-
//# sourceMappingURL=http.get.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.get.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.get.ts"],"names":[],"mappings":";;;AACA,2DAI4B;AAC5B,mFAG2C;AAE3C,SAAgB,GAAG,CAAC,QAAkB,EAAE,OAA0B;IAChE,OAAO,CAAC,GAAG,IAAuB,EAAiB,EAAE;QACnD,MAAM,iBAAiB,GAAG,IAAA,uDAA0B,EAClD,GAAG,QAAQ,GAAG,EACd,GAAG,IAAI,CACR,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,qCAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;QAEjE;;;WAGG;QACH,OAAO,CAAC,GAAG,EAAE,CAAA;QAEb,OAAO,OAAO,CAAA;IAChB,CAAC,CAAA;AACH,CAAC;AAhBD,kBAgBC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ClientRequest } from 'http';
|
|
2
|
-
import { NodeClientOptions, Protocol } from './NodeClientRequest';
|
|
3
|
-
import { ClientRequestArgs } from './utils/normalizeClientRequestArgs';
|
|
4
|
-
export declare function request(protocol: Protocol, options: NodeClientOptions): (...args: ClientRequestArgs) => ClientRequest;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.request = void 0;
|
|
4
|
-
const debug_1 = require("debug");
|
|
5
|
-
const NodeClientRequest_1 = require("./NodeClientRequest");
|
|
6
|
-
const normalizeClientRequestArgs_1 = require("./utils/normalizeClientRequestArgs");
|
|
7
|
-
const log = (0, debug_1.debug)('http request');
|
|
8
|
-
function request(protocol, options) {
|
|
9
|
-
return (...args) => {
|
|
10
|
-
log('request call (protocol "%s"):', protocol, args);
|
|
11
|
-
const clientRequestArgs = (0, normalizeClientRequestArgs_1.normalizeClientRequestArgs)(`${protocol}:`, ...args);
|
|
12
|
-
return new NodeClientRequest_1.NodeClientRequest(clientRequestArgs, options);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
exports.request = request;
|
|
16
|
-
//# sourceMappingURL=http.request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http.request.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/http.request.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAE7B,2DAI4B;AAC5B,mFAG2C;AAE3C,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,cAAc,CAAC,CAAA;AAEjC,SAAgB,OAAO,CAAC,QAAkB,EAAE,OAA0B;IACpE,OAAO,CAAC,GAAG,IAAuB,EAAiB,EAAE;QACnD,GAAG,CAAC,+BAA+B,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAA;QAEpD,MAAM,iBAAiB,GAAG,IAAA,uDAA0B,EAClD,GAAG,QAAQ,GAAG,EACd,GAAG,IAAI,CACR,CAAA;QACD,OAAO,IAAI,qCAAiB,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAA;IAC1D,CAAC,CAAA;AACH,CAAC;AAVD,0BAUC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import http from 'http';
|
|
3
|
-
import https from 'https';
|
|
4
|
-
import { HttpRequestEventMap } from '../../glossary';
|
|
5
|
-
import { Interceptor } from '../../Interceptor';
|
|
6
|
-
import { AsyncEventEmitter } from '../../utils/AsyncEventEmitter';
|
|
7
|
-
import { Protocol } from './NodeClientRequest';
|
|
8
|
-
export declare type ClientRequestEmitter = AsyncEventEmitter<HttpRequestEventMap>;
|
|
9
|
-
export declare type ClientRequestModules = Map<Protocol, typeof http | typeof https>;
|
|
10
|
-
/**
|
|
11
|
-
* Intercept requests made via the `ClientRequest` class.
|
|
12
|
-
* Such requests include `http.get`, `https.request`, etc.
|
|
13
|
-
*/
|
|
14
|
-
export declare class ClientRequestInterceptor extends Interceptor<HttpRequestEventMap> {
|
|
15
|
-
static symbol: symbol;
|
|
16
|
-
private modules;
|
|
17
|
-
constructor();
|
|
18
|
-
protected setup(): void;
|
|
19
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ClientRequestInterceptor = void 0;
|
|
7
|
-
const http_1 = __importDefault(require("http"));
|
|
8
|
-
const https_1 = __importDefault(require("https"));
|
|
9
|
-
const Interceptor_1 = require("../../Interceptor");
|
|
10
|
-
const http_get_1 = require("./http.get");
|
|
11
|
-
const http_request_1 = require("./http.request");
|
|
12
|
-
/**
|
|
13
|
-
* Intercept requests made via the `ClientRequest` class.
|
|
14
|
-
* Such requests include `http.get`, `https.request`, etc.
|
|
15
|
-
*/
|
|
16
|
-
class ClientRequestInterceptor extends Interceptor_1.Interceptor {
|
|
17
|
-
constructor() {
|
|
18
|
-
super(ClientRequestInterceptor.symbol);
|
|
19
|
-
this.modules = new Map();
|
|
20
|
-
this.modules.set('http', http_1.default);
|
|
21
|
-
this.modules.set('https', https_1.default);
|
|
22
|
-
}
|
|
23
|
-
setup() {
|
|
24
|
-
const log = this.log.extend('setup');
|
|
25
|
-
for (const [protocol, requestModule] of this.modules) {
|
|
26
|
-
const { request: pureRequest, get: pureGet } = requestModule;
|
|
27
|
-
this.subscriptions.push(() => {
|
|
28
|
-
requestModule.request = pureRequest;
|
|
29
|
-
requestModule.get = pureGet;
|
|
30
|
-
log('native "%s" module restored!', protocol);
|
|
31
|
-
});
|
|
32
|
-
const options = {
|
|
33
|
-
emitter: this.emitter,
|
|
34
|
-
log: this.log,
|
|
35
|
-
};
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
requestModule.request =
|
|
38
|
-
// Force a line break.
|
|
39
|
-
(0, http_request_1.request)(protocol, options);
|
|
40
|
-
// @ts-ignore
|
|
41
|
-
requestModule.get =
|
|
42
|
-
// Force a line break.
|
|
43
|
-
(0, http_get_1.get)(protocol, options);
|
|
44
|
-
log('native "%s" module patched!', protocol);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
exports.ClientRequestInterceptor = ClientRequestInterceptor;
|
|
49
|
-
ClientRequestInterceptor.symbol = Symbol('http');
|
|
50
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interceptors/ClientRequest/index.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAuB;AACvB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C;IACH,CAAC;;AA1CH,4DA2CC;AA1CQ,+BAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { IncomingMessage } from 'http';
|
|
3
|
-
export declare const IS_CLONE: unique symbol;
|
|
4
|
-
export interface ClonedIncomingMessage extends IncomingMessage {
|
|
5
|
-
[IS_CLONE]: boolean;
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* Clones a given `http.IncomingMessage` instance.
|
|
9
|
-
*/
|
|
10
|
-
export declare function cloneIncomingMessage(message: IncomingMessage): ClonedIncomingMessage;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cloneIncomingMessage = exports.IS_CLONE = void 0;
|
|
4
|
-
const http_1 = require("http");
|
|
5
|
-
const stream_1 = require("stream");
|
|
6
|
-
exports.IS_CLONE = Symbol('isClone');
|
|
7
|
-
/**
|
|
8
|
-
* Clones a given `http.IncomingMessage` instance.
|
|
9
|
-
*/
|
|
10
|
-
function cloneIncomingMessage(message) {
|
|
11
|
-
const clone = message.pipe(new stream_1.PassThrough());
|
|
12
|
-
// Inherit all direct "IncomingMessage" properties.
|
|
13
|
-
inheritProperties(message, clone);
|
|
14
|
-
// Deeply inherit the message prototypes (Readable, Stream, EventEmitter, etc.).
|
|
15
|
-
const clonedPrototype = Object.create(http_1.IncomingMessage.prototype);
|
|
16
|
-
getPrototypes(clone).forEach((prototype) => {
|
|
17
|
-
inheritProperties(prototype, clonedPrototype);
|
|
18
|
-
});
|
|
19
|
-
Object.setPrototypeOf(clone, clonedPrototype);
|
|
20
|
-
Object.defineProperty(clone, exports.IS_CLONE, {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
value: true,
|
|
23
|
-
});
|
|
24
|
-
return clone;
|
|
25
|
-
}
|
|
26
|
-
exports.cloneIncomingMessage = cloneIncomingMessage;
|
|
27
|
-
/**
|
|
28
|
-
* Returns a list of all prototypes the given object extends.
|
|
29
|
-
*/
|
|
30
|
-
function getPrototypes(source) {
|
|
31
|
-
const prototypes = [];
|
|
32
|
-
let current = source;
|
|
33
|
-
while ((current = Object.getPrototypeOf(current))) {
|
|
34
|
-
prototypes.push(current);
|
|
35
|
-
}
|
|
36
|
-
return prototypes;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Inherits a given target object properties and symbols
|
|
40
|
-
* onto the given source object.
|
|
41
|
-
* @param source Object which should acquire properties.
|
|
42
|
-
* @param target Object to inherit the properties from.
|
|
43
|
-
*/
|
|
44
|
-
function inheritProperties(source, target) {
|
|
45
|
-
const properties = [
|
|
46
|
-
...Object.getOwnPropertyNames(source),
|
|
47
|
-
...Object.getOwnPropertySymbols(source),
|
|
48
|
-
];
|
|
49
|
-
for (const property of properties) {
|
|
50
|
-
if (target.hasOwnProperty(property)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const descriptor = Object.getOwnPropertyDescriptor(source, property);
|
|
54
|
-
if (!descriptor) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
Object.defineProperty(target, property, descriptor);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=cloneIncomingMessage.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cloneIncomingMessage.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/cloneIncomingMessage.ts"],"names":[],"mappings":";;;AAAA,+BAAsC;AACtC,mCAAoC;AAEvB,QAAA,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,CAAA;AAMzC;;GAEG;AACH,SAAgB,oBAAoB,CAClC,OAAwB;IAExB,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,oBAAW,EAAE,CAAC,CAAA;IAE7C,mDAAmD;IACnD,iBAAiB,CAAC,OAAO,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M,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;KACpD;AACH,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Request } from '@remix-run/web-fetch';
|
|
2
|
-
import type { NodeClientRequest } from '../NodeClientRequest';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a Fetch API `Request` instance from the given `http.ClientRequest`.
|
|
5
|
-
*/
|
|
6
|
-
export declare function createRequest(clientRequest: NodeClientRequest): Request;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createRequest = void 0;
|
|
4
|
-
const web_fetch_1 = require("@remix-run/web-fetch");
|
|
5
|
-
const headers_polyfill_1 = require("headers-polyfill");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a Fetch API `Request` instance from the given `http.ClientRequest`.
|
|
8
|
-
*/
|
|
9
|
-
function createRequest(clientRequest) {
|
|
10
|
-
const headers = new headers_polyfill_1.Headers();
|
|
11
|
-
const outgoingHeaders = clientRequest.getHeaders();
|
|
12
|
-
for (const headerName in outgoingHeaders) {
|
|
13
|
-
const headerValue = outgoingHeaders[headerName];
|
|
14
|
-
if (!headerValue) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
const valuesList = Array.prototype.concat([], headerValue);
|
|
18
|
-
for (const value of valuesList) {
|
|
19
|
-
headers.append(headerName, value.toString());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return new web_fetch_1.Request(clientRequest.url, {
|
|
23
|
-
method: clientRequest.method || 'GET',
|
|
24
|
-
headers,
|
|
25
|
-
credentials: 'same-origin',
|
|
26
|
-
body: clientRequest.requestBuffer,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
exports.createRequest = createRequest;
|
|
30
|
-
//# sourceMappingURL=createRequest.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createRequest.ts"],"names":[],"mappings":";;;AAAA,oDAA8C;AAC9C,uDAA0C;AAG1C;;GAEG;AACH,SAAgB,aAAa,CAAC,aAAgC;IAC5D,MAAM,OAAO,GAAG,IAAI,0BAAO,EAAE,CAAA;IAE7B,MAAM,eAAe,GAAG,aAAa,CAAC,UAAU,EAAE,CAAA;IAClD,KAAK,MAAM,UAAU,IAAI,eAAe,EAAE;QACxC,MAAM,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;QAE/C,IAAI,CAAC,WAAW,EAAE;YAChB,SAAQ;SACT;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,CAAA;QAC1D,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAA;SAC7C;KACF;IAED,OAAO,IAAI,mBAAO,CAAC,aAAa,CAAC,GAAG,EAAE;QACpC,MAAM,EAAE,aAAa,CAAC,MAAM,IAAI,KAAK;QACrC,OAAO;QACP,WAAW,EAAE,aAAa;QAC1B,IAAI,EAAE,aAAa,CAAC,aAAa;KAClC,CAAC,CAAA;AACJ,CAAC;AAvBD,sCAuBC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import type { IncomingMessage } from 'http';
|
|
3
|
-
import { Response } from '@remix-run/web-fetch';
|
|
4
|
-
/**
|
|
5
|
-
* Creates a Fetch API `Response` instance from the given
|
|
6
|
-
* `http.IncomingMessage` instance.
|
|
7
|
-
*/
|
|
8
|
-
export declare function createResponse(message: IncomingMessage): Response;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createResponse = void 0;
|
|
4
|
-
const web_fetch_1 = require("@remix-run/web-fetch");
|
|
5
|
-
const headers_polyfill_1 = require("headers-polyfill");
|
|
6
|
-
/**
|
|
7
|
-
* Creates a Fetch API `Response` instance from the given
|
|
8
|
-
* `http.IncomingMessage` instance.
|
|
9
|
-
*/
|
|
10
|
-
function createResponse(message) {
|
|
11
|
-
const readable = new web_fetch_1.ReadableStream({
|
|
12
|
-
start(controller) {
|
|
13
|
-
message.on('data', (chunk) => controller.enqueue(chunk));
|
|
14
|
-
message.on('end', () => controller.close());
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
return new web_fetch_1.Response(readable, {
|
|
18
|
-
status: message.statusCode,
|
|
19
|
-
statusText: message.statusMessage,
|
|
20
|
-
headers: (0, headers_polyfill_1.objectToHeaders)(message.headers),
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.createResponse = createResponse;
|
|
24
|
-
//# sourceMappingURL=createResponse.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createResponse.js","sourceRoot":"","sources":["../../../../src/interceptors/ClientRequest/utils/createResponse.ts"],"names":[],"mappings":";;;AACA,oDAA+D;AAC/D,uDAAkD;AAElD;;;GAGG;AACH,SAAgB,cAAc,CAAC,OAAwB;IACrD,MAAM,QAAQ,GAAG,IAAI,0BAAc,CAAC;QAClC,KAAK,CAAC,UAAU;YACd,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;YACxD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAA;QAC7C,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,IAAI,oBAAQ,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,OAAO,CAAC,UAAU;QAC1B,UAAU,EAAE,OAAO,CAAC,aAAa;QACjC,OAAO,EAAE,IAAA,kCAAe,EAAC,OAAO,CAAC,OAAO,CAAC;KAC1C,CAAC,CAAA;AACJ,CAAC;AAbD,wCAaC"}
|