Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-http-proxy-json

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-http-proxy-json - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

17

index.js

@@ -6,2 +6,5 @@ 'use strict';

const BufferHelper = require('bufferhelper');
const isString = function (obj) {
return Object.prototype.toString.call(obj) === '[object String]';
}

@@ -75,3 +78,2 @@ /**

body = data.toString();
console.log('JSON.parse error:', e);
}

@@ -85,4 +87,8 @@

let finish = _body => {
// empty response body
if (!_body) {
_body = '';
}
// Converts the JSON to buffer.
let body = new Buffer(JSON.stringify(_body));
let body = new Buffer(isString(_body) ? _body : JSON.stringify(_body));

@@ -121,3 +127,2 @@ // Call the response method and recover the content-encoding.

body = buffer.toBuffer().toString();
console.log('JSON.parse error:', e);
}

@@ -131,4 +136,8 @@

let finish = _body => {
// empty response body
if (!_body) {
_body = '';
}
// Converts the JSON to buffer.
let body = new Buffer(JSON.stringify(_body));
let body = new Buffer(isString(_body) ? _body : JSON.stringify(_body));

@@ -135,0 +144,0 @@ // Call the response method

{
"name": "node-http-proxy-json",
"version": "0.1.7",
"version": "0.1.8",
"description": "for node-http-proxy transform the response json from the proxied server.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,2 +16,6 @@ 'use strict';

const isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
describe('modifyResponse--brotli', function() {

@@ -78,3 +82,3 @@ if (typeof zlib.createBrotliCompress !== 'function') {

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -117,3 +121,3 @@ body.age = 2;

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -120,0 +124,0 @@ body.age = 2;

@@ -16,2 +16,6 @@ 'use strict';

const isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
describe('modifyResponse--deflate', () => {

@@ -32,3 +36,3 @@ let proxy, server, targetServer;

targetServer = http
.createServer(function(req, res) {
.createServer(function (req, res) {
// Create deflated content

@@ -74,3 +78,3 @@ let deflate = zlib.Deflate();

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -92,6 +96,6 @@ body.age = 2;

inflate
.on('data', function(chunk) {
.on('data', function (chunk) {
body += chunk;
})
.on('end', function() {
.on('end', function () {
assert.equal(

@@ -113,3 +117,3 @@ JSON.stringify({ name: 'node-http-proxy-json', age: 2 }),

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -131,6 +135,6 @@ body.age = 2;

inflate
.on('data', function(chunk) {
.on('data', function (chunk) {
body += chunk;
})
.on('end', function() {
.on('end', function () {
assert.equal(

@@ -137,0 +141,0 @@ JSON.stringify({ name: 'node-http-proxy-json', age: 2 }),

@@ -15,4 +15,7 @@ 'use strict';

const TARGET_SERVER_PORT = 5001;
const isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
describe('modifyResponse--gzip', function() {
describe('modifyResponse--gzip', function () {
let proxy, server, targetServer;

@@ -74,3 +77,3 @@ beforeEach(() => {

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -113,3 +116,3 @@ body.age = 2;

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -116,0 +119,0 @@ body.age = 2;

@@ -15,4 +15,7 @@ 'use strict';

const TARGET_SERVER_PORT = 5005;
const isObject = function (obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}
describe('modifyResponse--uncompressed', function() {
describe('modifyResponse--uncompressed', function () {
let proxy, server, targetServer;

@@ -55,5 +58,5 @@ beforeEach(() => {

// Listen for the `proxyRes` event on `proxy`.
proxy.on('proxyRes', function(proxyRes, req, res) {
proxy.on('proxyRes', function (proxyRes, req, res) {
modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -88,3 +91,3 @@ body.age = 2;

modifyResponse(res, proxyRes, body => {
if (body) {
if (isObject(body)) {
// modify some information

@@ -91,0 +94,0 @@ body.age = 2;

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