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

foxy

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

foxy - npm Package Compare versions

Comparing version 11.0.4 to 11.1.0

19

lib/config.js

@@ -53,3 +53,3 @@ "use strict";

/**
* Proxy Options.
* Proxy Options that get passed along to http-proxy
*/

@@ -64,3 +64,18 @@ proxyOptions: {

ws: true
}
},
/**
* Any transformations to occur after the server has sent
* its response
*/
proxyRes: [
utils.checkCookies,
utils.removeExcludedHeaders,
utils.handleRedirect
],
/**
* Remove content-length headers as we've rewritten the response
*/
excludedHeaders: [
"content-length", "content-encoding"
]
};

@@ -67,0 +82,0 @@

92

lib/utils.js
"use stict";
var url = require("url");
var path = require("path");
var cookie = require("cookie");
var url = require("url");
var path = require("path");
var cookie = require("cookie");
var excludeList = require("./exclude");
var utils = exports;
/**
* Remove Headers from a response, this allow
* @param {Object} headers
* @param {Array} items
* @param {Object} res
* @param {Object} req
* @param {Object} config
*/
function removeHeaders(headers, items) {
items.forEach(function (item) {
if (headers.hasOwnProperty(item)) {
delete headers[item];
utils.removeExcludedHeaders = function removeHeaders (res, req, config) {
config.excludedHeaders.forEach(function (item) {
if (res.headers.hasOwnProperty(item)) {
delete res.headers[item];
}
});
}
};

@@ -24,3 +25,3 @@ /**

*/
function getProxyHost(opts) {
utils.getProxyHost = function getProxyHost(opts) {
if (opts.port && opts.port !== 80) {

@@ -30,3 +31,3 @@ return opts.hostname + ":" + opts.port;

return opts.hostname;
}
};

@@ -38,3 +39,3 @@ /**

*/
function rewriteCookies(rawCookie) {
utils.rewriteCookies = function rewriteCookies(rawCookie) {

@@ -62,3 +63,3 @@ var parsed = cookie.parse(rawCookie, {

return pairs.join("; ");
}
};

@@ -70,3 +71,3 @@ /**

*/
function rewriteLinks(userServer, proxyUrl) {
utils.rewriteLinks = function rewriteLinks(userServer, proxyUrl) {

@@ -144,3 +145,3 @@ var host = userServer.hostname;

};
}
};

@@ -151,3 +152,3 @@ /**

*/
function handleIe(req, res, next) {
utils.handleIe = function handleIe(req, res, next) {

@@ -177,3 +178,3 @@ var ua = req.headers["user-agent"];

return req;
}
};

@@ -185,4 +186,4 @@ /**

*/
function getRules(config, host) {
var rules = [rewriteLinks(config.urlObj, host)];
utils.getRules = function getRules(config, host) {
var rules = [utils.rewriteLinks(config.urlObj, host)];
if (config.rules && config.rules.length) {

@@ -198,3 +199,3 @@ var conf = config.rules;

return rules;
}
};

@@ -204,29 +205,16 @@ /**

* @param {Object} res
* @param {Object} req
* @param {Immutable.Map} config
*/
function checkCookies(res, config) {
utils.checkCookies = function checkCookies(res, req, config) {
if (typeof(res.headers["set-cookie"]) !== "undefined") {
if (config.cookies && config.cookies.stripDomain) {
res.headers["set-cookie"] = res.headers["set-cookie"].map(function (item) {
return rewriteCookies(item);
return utils.rewriteCookies(item);
});
}
}
}
};
/**
* Perform any required transformations on the `res` object before it gets back to
* the browser
* @param config
*/
function proxyRes(config) {
return function (res, req) {
checkCookies(res, config);
removeHeaders(res.headers, ["content-length", "content-encoding"]);
handleRedirect(res, req, config);
};
}
/**
* If any redirects contain the HOST of the target or req, rewrite it,

@@ -238,3 +226,3 @@ * otherwise let it through

var redirectRegex = /^30(1|2|7|8)$/;
function handleRedirect (proxyRes, req, config) {
utils.handleRedirect = function handleRedirect (proxyRes, req, config) {

@@ -253,13 +241,15 @@ var whitelist = [

}
}
};
module.exports = {
rewriteLinks: rewriteLinks,
rewriteCookies: rewriteCookies,
getProxyHost: getProxyHost,
removeHeaders: removeHeaders,
handleIe: handleIe,
getRules: getRules,
proxyRes: proxyRes,
handleRedirect: handleRedirect
};
/**
* Perform any required transformations on the proxyRes `res` object before it gets back to
* the browser
* @param config
*/
utils.proxyRes = function proxyRes(config) {
return function (res, req) {
config.proxyRes.forEach(function (func) {
func(res, req, config);
});
};
};
{
"name": "foxy",
"version": "11.0.4",
"version": "11.1.0",
"description": "Proxy with response modding",

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

@@ -68,3 +68,20 @@ ##Foxy

## proxyResponse middleware
You can add middleware-like functions which process the proxy response.
```js
var foxy = require("foxy");
var config = {
proxyRes: [
function(proxyRes, req, config) {
// do something with the proxyRes object which comes from node-http-proxy
}
]
};
var proxy = foxy("http://localhost:3000", config).listen(8000);
```
#TODO

@@ -71,0 +88,0 @@

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