Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
node-http-proxy-text
Advanced tools
Readme
for node-http-proxy transform the response json from the proxied server.
npm install node-http-proxy-json
When using node-http-proxy need to modify the response. If your proxy server returns HTML/XML document, you can try Harmon. But sometimes the proxy server only returns the JSON. For example, call API from the server. Usually the server will compress the data. So before using this repository, confirm your server compression format, currently only supports gzip、deflate and uncompressed. If you need other compression formats, please create a new Issue, and I will try to achieve it as much as possible.
var zlib = require('zlib');
var http = require('http');
var httpProxy = require('http-proxy');
var modifyResponse = require('node-http-proxy-json');
// Create a proxy server
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:5001'
});
// Listen for the `proxyRes` event on `proxy`.
proxy.on('proxyRes', function (proxyRes, req, res) {
modifyResponse(res, proxyRes, function (body) {
if (body) {
// modify some information
body.age = 2;
delete body.version;
}
return body; // return value can be a promise
});
});
// Create your server and then proxies the request
var server = http.createServer(function (req, res) {
proxy.web(req, res);
}).listen(5000);
// Create your target server
var targetServer = http.createServer(function (req, res) {
// Create gzipped content
var gzip = zlib.Gzip();
var _write = res.write;
var _end = res.end;
gzip.on('data', function (buf) {
_write.call(res, buf);
});
gzip.on('end', function () {
_end.call(res);
});
res.write = function (data) {
gzip.write(data);
};
res.end = function () {
gzip.end();
};
res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'gzip'});
res.write(JSON.stringify({name: 'node-http-proxy-json', age: 1, version: '1.0.0'}));
res.end();
}).listen(5001);
var zlib = require('zlib');
var http = require('http');
var httpProxy = require('http-proxy');
var modifyResponse = require('../');
// Create a proxy server
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:5001'
});
// Listen for the `proxyRes` event on `proxy`.
proxy.on('proxyRes', function (proxyRes, req, res) {
modifyResponse(res, proxyRes, function (body) {
if (body) {
// modify some information
body.age = 2;
delete body.version;
}
return body; // return value can be a promise
});
});
// Create your server and then proxies the request
var server = http.createServer(function (req, res) {
proxy.web(req, res);
}).listen(5000);
// Create your target server
var targetServer = http.createServer(function (req, res) {
// Create deflated content
var deflate = zlib.Deflate();
var _write = res.write;
var _end = res.end;
deflate.on('data', function (buf) {
_write.call(res, buf);
});
deflate.on('end', function () {
_end.call(res);
});
res.write = function (data) {
deflate.write(data);
};
res.end = function () {
deflate.end();
};
res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'deflate'});
res.write(JSON.stringify({name: 'node-http-proxy-json', age: 1, version: '1.0.0'}));
res.end();
}).listen(5001);
var http = require('http');
var httpProxy = require('http-proxy');
var modifyResponse = require('../');
// Create a proxy server
var proxy = httpProxy.createProxyServer({
target: 'http://localhost:5001'
});
// Listen for the `proxyRes` event on `proxy`.
proxy.on('proxyRes', function (proxyRes, req, res) {
modifyResponse(res, proxyRes, function (body) {
if (body) {
// modify some information
body.age = 2;
delete body.version;
}
return body; // return value can be a promise
});
});
// Create your server and then proxies the request
var server = http.createServer(function (req, res) {
proxy.web(req, res);
}).listen(5000);
// Create your target server
var targetServer = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'application/json', 'Content-Encoding': 'deflate'});
res.write(JSON.stringify({name: 'node-http-proxy-json', age: 1, version: '1.0.0'}));
res.end();
}).listen(5001);
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test
FAQs
Modify node-http-proxy response’s text
The npm package node-http-proxy-text receives a total of 0 weekly downloads. As such, node-http-proxy-text popularity was classified as not popular.
We found that node-http-proxy-text demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.