@pollyjs/adapter-node-http
Advanced tools
Comparing version 2.6.3 to 2.7.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [2.7.0](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/compare/v2.6.3...v2.7.0) (2019-11-21) | ||
### Bug Fixes | ||
* **adapter-node-http:** Correctly handle uploading binary data ([#257](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/issues/257)) ([31f0e0a](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/commit/31f0e0a)) | ||
### Features | ||
* **adapter-node-http:** Upgrade nock to v11.x ([#273](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/issues/273)) ([5d42cbd](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/commit/5d42cbd)) | ||
## [2.6.3](https://github.com/netflix/pollyjs/tree/master/packages/@pollyjs/adapter-node-http/compare/v2.6.2...v2.6.3) (2019-09-30) | ||
@@ -8,0 +24,0 @@ |
{ | ||
"name": "@pollyjs/adapter-node-http", | ||
"version": "2.6.3", | ||
"version": "2.7.0", | ||
"description": "Node HTTP adapter for @pollyjs", | ||
@@ -49,4 +49,3 @@ "main": "dist/cjs/pollyjs-adapter-node-http.js", | ||
"lodash-es": "^4.17.11", | ||
"nock": "^10.0.6", | ||
"semver": "^6.1.1" | ||
"nock": "^11.7.0" | ||
}, | ||
@@ -56,6 +55,8 @@ "devDependencies": { | ||
"@pollyjs/persister-fs": "^2.6.3", | ||
"form-data": "^2.5.1", | ||
"get-stream": "^5.1.0", | ||
"node-fetch": "^2.6.0", | ||
"rollup": "^1.14.6" | ||
}, | ||
"gitHead": "77c42d4576fc113e51b5fca6d1dab5628db23e6b" | ||
"gitHead": "89baa70636786d22c6115bd7e5d5af415202d4d9" | ||
} |
import http from 'http'; | ||
import https from 'https'; | ||
import URL from 'url'; | ||
import { Readable } from 'stream'; | ||
import { URL } from 'url'; | ||
import { Readable as ReadableStream } from 'stream'; | ||
import nock from 'nock'; | ||
import semver from 'semver'; | ||
import { | ||
normalizeClientRequestArgs, | ||
isUtf8Representable, | ||
isContentEncoded, | ||
isJSONContent | ||
} from 'nock/lib/common'; | ||
import Adapter from '@pollyjs/adapter'; | ||
import { HTTP_METHODS } from '@pollyjs/utils'; | ||
import parseRequestArguments from './utils/parse-request-arguments'; | ||
import getUrlFromOptions from './utils/get-url-from-options'; | ||
import isBinaryBuffer from './utils/is-binary-buffer'; | ||
import isContentEncoded from './utils/is-content-encoded'; | ||
import mergeChunks from './utils/merge-chunks'; | ||
import urlToOptions from './utils/url-to-options'; | ||
@@ -66,3 +69,3 @@ const IS_STUBBED = Symbol(); | ||
const { headers } = req; | ||
const parsedArguments = parseRequestArguments( | ||
const parsedArguments = normalizeClientRequestArgs( | ||
...REQUEST_ARGUMENTS.get(req) | ||
@@ -72,7 +75,15 @@ ); | ||
// body will always be a string unless the content-type is application/json | ||
// in which nock will then parse into an object. We have our own way of | ||
// dealing with json content to convert it back to a string. | ||
if (body && typeof body !== 'string') { | ||
body = JSON.stringify(body); | ||
if (body) { | ||
if ( | ||
typeof body === 'string' && | ||
!isUtf8Representable(Buffer.from(body, 'hex')) | ||
) { | ||
// Nock internally converts a binary buffer into its hexadecimal | ||
// representation so convert it back to a buffer. | ||
body = Buffer.from(body, 'hex'); | ||
} else if (isJSONContent(headers)) { | ||
// Nock will parse json content into an object. We have our own way | ||
// of dealing with json content so convert it back to a string. | ||
body = JSON.stringify(body); | ||
} | ||
} | ||
@@ -114,13 +125,10 @@ | ||
// Patch http.request, http.get, https.request, and https.get | ||
// to support new Node.js 10.9 signature `http.request(url[, options][, callback])` | ||
// (https://github.com/nock/nock/issues/1227). | ||
// | ||
// This patch is also needed to set some default values which nock doesn't | ||
// properly set. | ||
// to set some default values which nock doesn't properly set. | ||
Object.keys(modules).forEach(moduleName => { | ||
const module = modules[moduleName]; | ||
const { request, get, globalAgent } = module; | ||
const parseArgs = function() { | ||
const args = parseRequestArguments(...arguments); | ||
function parseArgs() { | ||
const args = normalizeClientRequestArgs(...arguments); | ||
if (moduleName === 'https') { | ||
@@ -139,3 +147,3 @@ args.options = { | ||
return args; | ||
}; | ||
} | ||
@@ -148,9 +156,7 @@ module.request = function _request() { | ||
if (semver.satisfies(process.version, '>=8')) { | ||
module.get = function _get() { | ||
const { options, callback } = parseArgs(...arguments); | ||
module.get = function _get() { | ||
const { options, callback } = parseArgs(...arguments); | ||
return get(options, callback); | ||
}; | ||
} | ||
return get(options, callback); | ||
}; | ||
}); | ||
@@ -168,3 +174,3 @@ } | ||
headers: { ...headers }, | ||
...URL.parse(pollyRequest.url) | ||
...urlToOptions(new URL(pollyRequest.url)) | ||
}); | ||
@@ -208,8 +214,4 @@ | ||
// correctly handle it. | ||
// https://github.com/nock/nock/blob/v10.0.6/lib/request_overrider.js#L394-L397 | ||
respond(error); | ||
// This allows the consumer to handle the error gracefully | ||
req.emit('error', error); | ||
return; | ||
@@ -220,3 +222,3 @@ } | ||
const chunks = this.getChunksFromBody(body, headers); | ||
const stream = new Readable(); | ||
const stream = new ReadableStream(); | ||
@@ -273,3 +275,3 @@ // Expose the response data as a stream of chunks since | ||
// 2. A string buffer. | ||
return buffer.toString(isBinaryBuffer(buffer) ? 'hex' : 'utf8'); | ||
return buffer.toString(isUtf8Representable(buffer) ? 'utf8' : 'hex'); | ||
} | ||
@@ -299,4 +301,4 @@ | ||
// 2. A utf8 string which means a regular string. | ||
return [Buffer.from(buffer, isBinaryBuffer(buffer) ? 'hex' : 'utf8')]; | ||
return [Buffer.from(buffer, isUtf8Representable(buffer) ? 'utf8' : 'hex')]; | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 5 instances in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
5374079
4
39588
6
16
30
25
+ Addednock@11.9.1(transitive)
+ Addedpropagate@2.0.1(transitive)
- Removedsemver@^6.1.1
- Removedassertion-error@1.1.0(transitive)
- Removedchai@4.5.0(transitive)
- Removedcheck-error@1.0.3(transitive)
- Removeddeep-eql@4.1.4(transitive)
- Removeddeep-equal@1.1.2(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-func-name@2.0.2(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedis-arguments@1.1.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedloupe@2.3.7(transitive)
- Removednock@10.0.6(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedpathval@1.1.1(transitive)
- Removedpropagate@1.0.0(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsemver@5.7.26.3.1(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedtype-detect@4.1.0(transitive)
Updatednock@^11.7.0