@pollyjs/adapter-node-http
Advanced tools
Comparing version 4.0.4 to 4.1.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [4.1.0](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/compare/v4.0.4...v4.1.0) (2020-04-23) | ||
### Bug Fixes | ||
* Improve abort handling ([#320](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/issues/320)) ([cc46bb4](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/commit/cc46bb4)) | ||
## [4.0.4](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/compare/v4.0.3...v4.0.4) (2020-03-21) | ||
@@ -8,0 +19,0 @@ |
{ | ||
"name": "@pollyjs/adapter-node-http", | ||
"version": "4.0.4", | ||
"version": "4.1.0", | ||
"description": "Node HTTP adapter for @pollyjs", | ||
@@ -46,4 +46,4 @@ "main": "dist/cjs/pollyjs-adapter-node-http.js", | ||
"dependencies": { | ||
"@pollyjs/adapter": "^4.0.4", | ||
"@pollyjs/utils": "^4.0.2", | ||
"@pollyjs/adapter": "^4.1.0", | ||
"@pollyjs/utils": "^4.1.0", | ||
"lodash-es": "^4.17.11", | ||
@@ -53,4 +53,4 @@ "nock": "^12.0.3" | ||
"devDependencies": { | ||
"@pollyjs/core": "^4.0.4", | ||
"@pollyjs/persister-fs": "^4.0.4", | ||
"@pollyjs/core": "^4.1.0", | ||
"@pollyjs/persister-fs": "^4.1.0", | ||
"form-data": "^2.5.1", | ||
@@ -61,3 +61,3 @@ "get-stream": "^5.1.0", | ||
}, | ||
"gitHead": "c2e9744df68698469e7e4e7f6668a75ac49d54c7" | ||
"gitHead": "ad603d322066cad75a79e43b5cb9fd6fc1196d4a" | ||
} |
@@ -20,2 +20,3 @@ import http from 'http'; | ||
const IS_STUBBED = Symbol(); | ||
const ABORT_HANDLER = Symbol(); | ||
const REQUEST_ARGUMENTS = new WeakMap(); | ||
@@ -155,2 +156,13 @@ | ||
onRequest(pollyRequest) { | ||
const { req } = pollyRequest.requestArguments; | ||
if (req.aborted) { | ||
pollyRequest.abort(); | ||
} else { | ||
pollyRequest[ABORT_HANDLER] = () => pollyRequest.abort(); | ||
req.once('abort', pollyRequest[ABORT_HANDLER]); | ||
} | ||
} | ||
async passthroughRequest(pollyRequest) { | ||
@@ -200,3 +212,16 @@ const { parsedArguments } = pollyRequest.requestArguments; | ||
const { req, respond } = pollyRequest.requestArguments; | ||
const { statusCode, body, headers } = pollyRequest.response; | ||
if (pollyRequest[ABORT_HANDLER]) { | ||
req.off('abort', pollyRequest[ABORT_HANDLER]); | ||
} | ||
if (pollyRequest.aborted) { | ||
// Even if the request has been aborted, we need to respond to the nock | ||
// request in order to resolve its awaiting promise. | ||
respond(null, [0, undefined, {}]); | ||
return; | ||
} | ||
if (error) { | ||
@@ -210,3 +235,2 @@ // If an error was received then forward it over to nock so it can | ||
const { statusCode, body, headers } = pollyRequest.response; | ||
const chunks = this.getChunksFromBody(body, headers); | ||
@@ -213,0 +237,0 @@ const stream = new ReadableStream(); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
5381122
39624
Updated@pollyjs/adapter@^4.1.0
Updated@pollyjs/utils@^4.1.0