Socket
Socket
Sign inDemoInstall

http-proxy

Package Overview
Dependencies
Maintainers
4
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-proxy - npm Package Compare versions

Comparing version 1.14.0 to 1.15.0

42

lib/http-proxy/common.js

@@ -7,3 +7,4 @@ var common = exports,

var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i,
isSSL = /^https|wss/;
isSSL = /^https|wss/,
cookieDomainRegex = /(;\s*domain=)([^;]+)/i;

@@ -53,2 +54,6 @@ /**

}
if (options.ca) {
outgoing.ca = options.ca;
}

@@ -203,2 +208,37 @@ if (isSSL.test(options[forward || 'target'].protocol)) {

/**
* Rewrites or removes the domain of a cookie header
*
* @param {String|Array} Header
* @param {Object} Config, mapping of domain to rewritten domain.
* '*' key to match any domain, null value to remove the domain.
*
* @api private
*/
common.rewriteCookieDomain = function rewriteCookieDomain(header, config) {
if (Array.isArray(header)) {
return header.map(function (headerElement) {
return rewriteCookieDomain(headerElement, config);
});
}
return header.replace(cookieDomainRegex, function(match, prefix, previousDomain) {
var newDomain;
if (previousDomain in config) {
newDomain = config[previousDomain];
} else if ('*' in config) {
newDomain = config['*'];
} else {
//no match, return previous domain
return match;
}
if (newDomain) {
//replace domain
return prefix + newDomain;
} else {
//remove domain
return '';
}
});
};
/**
* Check the host and see if it potentially has a port in it (keep it simple)

@@ -205,0 +245,0 @@ *

4

lib/http-proxy/passes/web-incoming.js

@@ -81,4 +81,4 @@ var http = require('http'),

});
req.headers['x-forwarded-host'] = req.headers['host'];
req.headers['x-forwarded-host'] = req.headers['host'] || '';
},

@@ -85,0 +85,0 @@

var url = require('url'),
common = require('../common'),
passes = exports;
var redirectRegex = /^30(1|2|7|8)$/;
var redirectRegex = /^201|30(1|2|7|8)$/;

@@ -80,9 +81,18 @@ /*!

* @param {proxyResponse} Res Response object from the proxy request
* @param {Object} Options options.cookieDomainRewrite: Config to rewrite cookie domain
*
* @api private
*/
function writeHeaders(req, res, proxyRes) {
function writeHeaders(req, res, proxyRes, options) {
var rewriteCookieDomainConfig = options.cookieDomainRewrite;
if (typeof rewriteCookieDomainConfig === 'string') { //also test for ''
rewriteCookieDomainConfig = { '*': rewriteCookieDomainConfig };
}
Object.keys(proxyRes.headers).forEach(function(key) {
if(proxyRes.headers[key] != undefined){
res.setHeader(String(key).trim(), proxyRes.headers[key]);
var header = proxyRes.headers[key];
if (header != undefined) {
if (rewriteCookieDomainConfig && key.toLowerCase() === 'set-cookie') {
header = common.rewriteCookieDomain(header, rewriteCookieDomainConfig);
}
res.setHeader(String(key).trim(), header);
}

@@ -102,3 +112,6 @@ });

function writeStatusCode(req, res, proxyRes) {
res.writeHead(proxyRes.statusCode);
res.statusCode = proxyRes.statusCode;
if(proxyRes.statusMessage) {
res.statusMessage = proxyRes.statusMessage;
}
}

@@ -105,0 +118,0 @@

{
"name": "http-proxy",
"version": "1.14.0",
"version": "1.15.0",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

@@ -96,3 +96,3 @@ <p align="center">

which apply transformations to both the `req` and `res` object.
The first pipeline (ingoing) is responsible for the creation and manipulation of the stream that connects your client to the target.
The first pipeline (incoming) is responsible for the creation and manipulation of the stream that connects your client to the target.
The second pipeline (outgoing) is responsible for the creation and manipulation of the stream that, from your target, returns data

@@ -338,5 +338,17 @@ to the client.

* **auth**: Basic authentication i.e. 'user:password' to compute an Authorization header.
* **hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects.
* **autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false.
* **protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null.
* **hostRewrite**: rewrites the location hostname on (201/301/302/307/308) redirects.
* **autoRewrite**: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
* **protocolRewrite**: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
* **cookieDomainRewrite**: rewrites domain of `set-cookie` headers. Possible values:
* `false` (default): disable cookie rewriting
* String: new domain, for example `cookieDomainRewrite: "new.domain"`. To remove the domain, use `cookieDomainRewrite: ""`.
* Object: mapping of domains to new domains, use `"*"` to match all domains.
For example keep one domain unchanged, rewrite one domain and remove other domains:
```
cookieDomainRewrite: {
"unchanged.domain": "unchanged.domain",
"old.domain": "new.domain",
"*": ""
}
```
* **headers**: object with extra headers to be added to target requests.

@@ -343,0 +355,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