Socket
Socket
Sign inDemoInstall

express-request-proxy

Package Overview
Dependencies
101
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.0 to 2.0.0

10

lib/proxy.js

@@ -104,3 +104,3 @@ var _ = require('lodash'),

for (var key in resp.headers) {
if (_.contains(discardApiResponseHeaders, key) === false) {
if (_.includes(discardApiResponseHeaders, key) === false) {
res.set(key, resp.headers[key]);

@@ -185,3 +185,5 @@ }

debug('writing original headers to cache');
options.cache.setex(cacheKey + '__headers', options.cacheMaxAge, JSON.stringify(headersToKeep));
options.cache.setex(cacheKey + '__headers',
options.cacheMaxAge,
JSON.stringify(headersToKeep));
}

@@ -240,5 +242,5 @@

if (_.isFunction(options.cache.readStream)) {
return options.cache.readStream(cacheKey).pipe(res);
options.cache.readStream(cacheKey).pipe(res);
return;
}
options.cache.get(cacheKey, function(_err, data) {

@@ -245,0 +247,0 @@ if (_err) return next(_err);

@@ -30,3 +30,4 @@ var parseUrl = require('url').parse;

if (_.isNumber(limits.maxRedirects)) {
if (_.isNumber(options.maxRedirects) === false || options.maxRedirects > limits.maxRedirects) {
if (_.isNumber(options.maxRedirects) === false ||
options.maxRedirects > limits.maxRedirects) {
requestOptions.maxRedirects = limits.maxRedirects;

@@ -81,4 +82,15 @@ }

if (req.headers && req.headers.host) {
var hostSplit = req.headers.host.split(':');
var host = hostSplit[0];
var port = hostSplit[1];
if (port) {
requestOptions.headers['x-forwarded-port'] = port;
}
requestOptions.headers['x-forwarded-host'] = host;
}
requestOptions.headers['x-forwarded-proto'] = req.secure ? 'https' : 'http';
requestOptions.headers['x-forwarded-port'] = req.secure ? '443' : '80';

@@ -103,4 +115,4 @@ // Default to accepting gzip encoding

function shouldPassthroughHeader(header) {
if (_.contains(BLOCK_HEADERS, header) === true) return false;
if (options.cache && _.contains(CACHE_HEADERS, header) === true) return false;
if (_.includes(BLOCK_HEADERS, header) === true) return false;
if (options.cache && _.includes(CACHE_HEADERS, header) === true) return false;

@@ -107,0 +119,0 @@ return true;

15

package.json
{
"name": "express-request-proxy",
"version": "1.2.0",
"version": "2.0.0",
"description": "Intelligent http proxy Express middleware",
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": "mocha --reporter spec --bail --check-leaks test/",

@@ -34,4 +35,4 @@ "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",

"debug": "^2.1.1",
"lodash": "^3.0.1",
"lru-cache": "^2.5.0",
"lodash": "^4.6.1",
"lru-cache": "^4.0.0",
"path-to-regexp": "^1.1.1",

@@ -47,8 +48,8 @@ "request": "^2.53.0",

"dash-assert": "^1.0.2",
"eslint": "^1.9.0",
"eslint-config-4front": "^1.0.1",
"eslint": "^2.3.0",
"eslint-config-4front": "^1.1.3",
"express": "^4.11.1",
"istanbul": "^0.3.5",
"istanbul": "^0.4.2",
"memory-cache-stream": "^1.0.4",
"mocha": "^2.1.0",
"mocha": "^2.4.5",
"shortid": "^2.1.3",

@@ -55,0 +56,0 @@ "sinon": "^1.15.4",

@@ -132,4 +132,4 @@ var assert = require('assert');

'Last-Modified': new Date().toUTCString(),
'Expires': new Date().toUTCString(),
'Etag': '345345345345'
Expires: new Date().toUTCString(),
Etag: '345345345345'
};

@@ -190,3 +190,3 @@

this.originHeaders = {
'ETag': '2435345345',
ETag: '2435345345',
'If-Modified-Since': (new Date()).toUTCString()

@@ -193,0 +193,0 @@ };

@@ -88,3 +88,3 @@ var assert = require('assert');

params: {
'0': 'path1/path2',
0: 'path1/path2',
version: 'v1'

@@ -129,5 +129,5 @@ }

headers: {
'cookie': 'should_not_passthrough',
cookie: 'should_not_passthrough',
'if-none-match': '345345',
'header1': '1'
header1: '1'
}

@@ -148,6 +148,6 @@ };

headers: {
'cookie': 'should_not_passthrough',
cookie: 'should_not_passthrough',
'if-none-match': 'should_not_passthrough',
'if-modified-since': 'should_not_passthrough',
'header1': '1'
header1: '1'
}

@@ -183,3 +183,2 @@ };

assert.equal(opts.headers['x-forwarded-proto'], 'https');
assert.equal(opts.headers['x-forwarded-port'], '443');

@@ -190,5 +189,21 @@ req.secure = false;

assert.equal(opts.headers['x-forwarded-proto'], 'http');
assert.equal(opts.headers['x-forwarded-port'], '80');
});
it('default headers appended host and port', function() {
var req = {
headers: {
host: 'localhost:8080'
}
};
var endpointOptions = {
url: 'http://someapi.com',
cache: {}
};
var opts = requestOptions(req, endpointOptions);
assert.equal(opts.headers['x-forwarded-host'], 'localhost');
assert.equal(opts.headers['x-forwarded-port'], '8080');
});
it('cannot exceed limit options', function() {

@@ -198,6 +213,6 @@ var req = {

headers: {
'cookie': 'should_not_passthrough',
cookie: 'should_not_passthrough',
'if-none-match': 'should_not_passthrough',
'if-modified-since': 'should_not_passthrough',
'header1': '1'
header1: '1'
}

@@ -204,0 +219,0 @@ };

@@ -24,10 +24,10 @@ var express = require('express');

switch (is(req, ['urlencoded', 'json'])) {
case 'urlencoded':
debug('parse api urlencoded body');
return bodyParser.urlencoded({extended: false})(req, res, next);
case 'json':
debug('parse api json body');
return bodyParser.json()(req, res, next);
default:
break;
case 'urlencoded':
debug('parse api urlencoded body');
return bodyParser.urlencoded({extended: false})(req, res, next);
case 'json':
debug('parse api json body');
return bodyParser.json()(req, res, next);
default:
break;
}

@@ -93,4 +93,3 @@ }

// if (err.status >= 500)
console.error(err.message);
process.stderr.write(err.message);
res.status(err.status).send(err.message);

@@ -97,0 +96,0 @@ };

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc