Socket
Socket
Sign inDemoInstall

@pollyjs/adapter-node-http

Package Overview
Dependencies
Maintainers
2
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pollyjs/adapter-node-http - npm Package Compare versions

Comparing version 2.6.3 to 2.7.0

src/utils/url-to-options.js

16

CHANGELOG.md

@@ -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 @@

9

package.json
{
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc