@mswjs/interceptors
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -14,3 +14,3 @@ /// <reference types="node" /> | ||
method: string; | ||
headers: HeadersObject; | ||
headers: Headers; | ||
body?: string; | ||
@@ -17,0 +17,0 @@ } |
@@ -159,3 +159,3 @@ "use strict"; | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var _a, chunk, encoding, callback, writtenRequestBody, resolvedRequestBody, outHeaders, resolvedRequestHeaders, requestHeaders, formattedRequest, _b, resolverError, mockedResponse, _c, headers, request, ClientRequest; | ||
var _a, chunk, encoding, callback, writtenRequestBody, resolvedRequestBody, outgoingHeaders, resolvedRequestHeaders, requesHeadersObject, requestHeaders, isoRequest, _b, resolverError, mockedResponse, _c, headers, request, ClientRequest; | ||
var _this = this; | ||
@@ -174,12 +174,16 @@ return __generator(this, function (_d) { | ||
debug('request resolved body', resolvedRequestBody); | ||
outHeaders = this.getHeaders(); | ||
resolvedRequestHeaders = Object.assign({}, outHeaders, options.headers); | ||
requestHeaders = resolvedRequestHeaders | ||
? headers_utils_1.reduceHeadersObject(resolvedRequestHeaders, function (headers, name, value) { | ||
headers[name.toLowerCase()] = value; | ||
return headers; | ||
}, {}) | ||
: {}; | ||
outgoingHeaders = this.getHeaders(); | ||
resolvedRequestHeaders = Object.assign({}, outgoingHeaders, options.headers); | ||
requesHeadersObject = Object.entries(resolvedRequestHeaders).reduce(function (headersObject, _a) { | ||
var _b = __read(_a, 2), name = _b[0], value = _b[1]; | ||
if (value) { | ||
var corcedValue = typeof value === 'number' ? value.toString() : value; | ||
headersObject[name.toLowerCase()] = corcedValue; | ||
} | ||
return headersObject; | ||
}, {}); | ||
debug('request headers object', requesHeadersObject); | ||
requestHeaders = new headers_utils_1.Headers(requesHeadersObject); | ||
debug('request headers', requestHeaders); | ||
formattedRequest = { | ||
isoRequest = { | ||
url: url, | ||
@@ -192,3 +196,3 @@ method: options.method || 'GET', | ||
return [4 /*yield*/, until_1.until(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, resolver(formattedRequest, response)]; | ||
return [2 /*return*/, resolver(isoRequest, response)]; | ||
}); }); }) | ||
@@ -250,3 +254,3 @@ // When the request middleware throws an exception, error the request. | ||
response.complete = true; | ||
observer.emit('response', formattedRequest, { | ||
observer.emit('response', isoRequest, { | ||
status: mockedResponse.status || 200, | ||
@@ -281,3 +285,3 @@ statusText: mockedResponse.statusText || 'OK', | ||
// onto the original request instance. | ||
inheritRequestHeaders_1.inheritRequestHeaders(request, outHeaders); | ||
inheritRequestHeaders_1.inheritRequestHeaders(request, outgoingHeaders); | ||
// Propagate a request body buffer written via `req.write()` | ||
@@ -298,3 +302,3 @@ // to the original request. | ||
_b = (_a = observer).emit; | ||
_c = ['response', formattedRequest]; | ||
_c = ['response', isoRequest]; | ||
_d = { | ||
@@ -301,0 +305,0 @@ status: response.statusCode || 200, |
@@ -57,3 +57,3 @@ "use strict"; | ||
window.fetch = function (input, init) { return __awaiter(void 0, void 0, void 0, function () { | ||
var ref, url, method, request, response, isomorphicResponse; | ||
var ref, url, method, isoRequest, response, isomorphicResponse; | ||
var _a; | ||
@@ -70,12 +70,12 @@ return __generator(this, function (_b) { | ||
method: method, | ||
headers: (init === null || init === void 0 ? void 0 : init.headers) ? headers_utils_1.headersToObject(new headers_utils_1.Headers(init.headers)) : {} | ||
headers: new headers_utils_1.Headers((init === null || init === void 0 ? void 0 : init.headers) || {}) | ||
}; | ||
return [4 /*yield*/, ref.text()]; | ||
case 1: | ||
request = (_a.body = _b.sent(), | ||
isoRequest = (_a.body = _b.sent(), | ||
_a); | ||
debug('isomorphic request', request); | ||
observer.emit('request', request); | ||
debug('isomorphic request', isoRequest); | ||
observer.emit('request', isoRequest); | ||
debug('awaiting for the mocked response...'); | ||
return [4 /*yield*/, resolver(request, ref)]; | ||
return [4 /*yield*/, resolver(isoRequest, ref)]; | ||
case 2: | ||
@@ -87,3 +87,3 @@ response = _b.sent(); | ||
debug('derived isomorphic response', isomorphicResponse); | ||
observer.emit('response', request, isomorphicResponse); | ||
observer.emit('response', isoRequest, isomorphicResponse); | ||
return [2 /*return*/, new Response(response.body, __assign(__assign({}, isomorphicResponse), { | ||
@@ -103,3 +103,4 @@ // `Response.headers` cannot be instantiated with the `Headers` polyfill. | ||
_b = (_a = observer).emit; | ||
_c = ['response', request]; | ||
_c = ['response', | ||
isoRequest]; | ||
return [4 /*yield*/, normalizeFetchResponse(response)]; | ||
@@ -106,0 +107,0 @@ case 1: |
@@ -207,11 +207,11 @@ "use strict"; | ||
// Create an intercepted request instance exposed to the request intercepting middleware. | ||
var request = { | ||
var isoRequest = { | ||
url: url, | ||
method: this.method, | ||
body: this.data, | ||
headers: headers_utils_1.headersToObject(this._requestHeaders), | ||
headers: this._requestHeaders, | ||
}; | ||
debug('awaiting mocked response...'); | ||
Promise.resolve(until_1.until(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, resolver(request, this)]; | ||
return [2 /*return*/, resolver(isoRequest, this)]; | ||
}); }); })).then(function (_a) { | ||
@@ -269,3 +269,3 @@ var _b; | ||
_this.trigger('loadend'); | ||
observer.emit('response', request, { | ||
observer.emit('response', isoRequest, { | ||
status: _this.status, | ||
@@ -309,3 +309,3 @@ statusText: _this.statusText, | ||
debug('original response finished'); | ||
observer.emit('response', request, { | ||
observer.emit('response', isoRequest, { | ||
status: originalRequest_1.status, | ||
@@ -312,0 +312,0 @@ statusText: originalRequest_1.statusText, |
{ | ||
"name": "@mswjs/interceptors", | ||
"description": "Low-level HTTP/HTTPS/XHR/fetch request interception library.", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"main": "lib/index.js", | ||
@@ -55,3 +55,3 @@ "typings": "lib/index.d.ts", | ||
"debug": "^4.3.0", | ||
"headers-utils": "^3.0.0", | ||
"headers-utils": "^3.0.2", | ||
"strict-event-emitter": "^0.2.0" | ||
@@ -58,0 +58,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
155236
2184
Updatedheaders-utils@^3.0.2