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

express-http-proxy

Package Overview
Dependencies
Maintainers
3
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-http-proxy - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

11

app/steps/decorateProxyReqOpts.js
'use strict';
var debug = require('debug')('express-http-proxy');
function defaultDecorator(proxyReqOptBuilder /*, userReq */) {

@@ -12,6 +14,7 @@ return proxyReqOptBuilder;

.resolve(resolverFn(container.proxy.reqBuilder, container.user.req))
.then(function(processedReqOpts) {
delete processedReqOpts.params;
container.proxy.reqBuilder = processedReqOpts;
return Promise.resolve(container);
.then(function (processedReqOpts) {
delete processedReqOpts.params;
container.proxy.reqBuilder = processedReqOpts;
debug('Request options (after processing):', JSON.stringify(processedReqOpts));
return Promise.resolve(container);
});

@@ -18,0 +21,0 @@ }

@@ -13,3 +13,3 @@ 'use strict';

return Promise
.resolve(resolverFn(container.proxy.reqBuilder, container.user.req))
.resolve(resolverFn(container.user.req, container.user.res))
.then(function (shouldIContinue) {

@@ -16,0 +16,0 @@ if (shouldIContinue) {

@@ -12,8 +12,12 @@ 'use strict';

.resolve(resolverFn(container.proxy.res))
.then(function(shouldSkipToNext) {
return (shouldSkipToNext) ? container.user.next() : Promise.resolve(container);
.then(function (shouldSkipToNext) {
if (shouldSkipToNext) {
container.user.res.expressHttpProxy = container.proxy;
return Promise.reject(container.user.next());
} else {
return Promise.resolve(container);
}
})
.catch(Promise.reject);
}
module.exports = maybeSkipToNextHandler;

@@ -13,3 +13,3 @@ 'use strict';

var protocol = Container.proxy.requestModule;
var proxyReq = protocol.request(reqOpt, function(rsp) {
var proxyReq = Container.proxy.req = protocol.request(reqOpt, function(rsp) {
if (options.stream) {

@@ -16,0 +16,0 @@ Container.proxy.res = rsp;

@@ -33,7 +33,2 @@ 'use strict';

// Skip proxy if filter is falsey. Loose equality so filters can return
// false, null, undefined, etc.
//if (!container.options.filter(req, res)) { return next(); }
filterUserRequest(container)

@@ -40,0 +35,0 @@ .then(buildProxyReq)

@@ -21,4 +21,4 @@ 'use strict';

proxy: {
req: {},
res: {},
req: undefined,
res: undefined,
resData: undefined, // from proxy res

@@ -25,0 +25,0 @@ bodyContent: undefined, // for proxy req

{
"name": "express-http-proxy",
"version": "1.4.0",
"version": "1.5.0",
"description": "http proxy middleware for express",

@@ -11,4 +11,4 @@ "engines": {

"test": "npm -s run mocha && npm run -s lint",
"test:debug": "mocha debug -R spec test --recursive",
"mocha": "mocha -R spec test --recursive",
"test:debug": "mocha debug -R spec test --recursive --exit",
"mocha": "mocha -R spec test --recursive --exit",
"lint": "eslint index.js **/*js"

@@ -37,5 +37,3 @@ },

"express": "^4.15.4",
"jscs": "^3.0.7",
"jshint": "^2.9.5",
"mocha": "^3.5.0",
"mocha": "^5.2.0",
"supertest": "^3.0.0"

@@ -42,0 +40,0 @@ },

@@ -42,3 +42,3 @@ # express-http-proxy [![NPM version](https://badge.fury.io/js/express-http-proxy.svg)](http://badge.fury.io/js/express-http-proxy) [![Build Status](https://travis-ci.org/villadora/express-http-proxy.svg?branch=master)](https://travis-ci.org/villadora/express-http-proxy) [![Dependency Status](https://gemnasium.com/villadora/express-http-proxy.svg)](https://gemnasium.com/villadora/express-http-proxy)

e.g.
```
```js
app.use(proxy('/reject-promise', {

@@ -53,3 +53,3 @@ proxyReqOptDecorator: function() {

```
```js
next('An arbitrary rejection messasage');

@@ -62,3 +62,3 @@ ```

```
```js
app.use('/', proxy('http://google.com'))

@@ -71,3 +71,3 @@ ```

```
```js
function selectProxyHost() {

@@ -77,3 +77,3 @@ return (new Date() % 2) ? 'http://google.com' : 'http://altavista.com';

app.use('/', proxy(selectProxyHost);
app.use('/', proxy(selectProxyHost));
```

@@ -130,5 +130,7 @@

#### filter
#### filter (supports Promises)
The ```filter``` option can be used to limit what requests are proxied. Return ```true``` to execute proxy.
The ```filter``` option can be used to limit what requests are proxied. Return
```true``` to continue to execute proxy; return false-y to skip proxy for this
request.

@@ -145,2 +147,18 @@ For example, if you only want to proxy get request:

Promise form:
```js
app.use(proxy('localhost:12346', {
filter: function (req, res) {
return new Promise(function (resolve) {
resolve(req.method === 'GET');
});
}
}));
```
Note that in the previous example, `resolve(false)` will execute the happy path
for filter here (skipping the rest of the proxy, and calling `next()`).
`reject()` will also skip the rest of proxy and call `next()`.
#### userResDecorator (was: intercept) (supports Promise)

@@ -360,4 +378,4 @@

Normally, your proxy request will be made on the same protocol as the original
request. If you'd like to force the proxy request to be https, use this
Normally, your proxy request will be made on the same protocol as the `host`
parameter. If you'd like to force the proxy request to be https, use this
option.

@@ -553,2 +571,5 @@

| --- | --- |
| 1.5.0 | Fixes bug in `filter` signature. Fix bug in skipToNextHandler, add expressHttpProxy value to user res when skipped. Add tests for host as ip address. |
| 1.4.0 | DEPRECATED. Critical bug in the `filter` api.|
| 1.3.0 | DEPRECATED. Critical bug in the `filter` api. `filter` now supports Promises. Update linter to eslint. |
| 1.2.0 | Auto-stream when no decorations are made to req/res. Improved docs, fixes issues in maybeSkipToNexthandler, allow authors to manage error handling. |

@@ -555,0 +576,0 @@ | 1.1.0 | Add step to allow response headers to be modified.

@@ -146,3 +146,3 @@ 'use strict';

var app = express();
app.use(proxy('httpbin.org', {
app.use(proxy('localhost:8109', {
reqBodyEncoding: 'utf-16'

@@ -154,3 +154,3 @@ }));

if (err) { throw err; }
assert.equal(res.body.headers['Accept-Charset'], 'utf-16');
assert.equal(res.body.headers['accept-charset'], 'utf-16');
done(err);

@@ -157,0 +157,0 @@ });

@@ -52,1 +52,20 @@ 'use strict';

});
describe('host can be an ip address', function () {
it('with a port', function (done) {
var app = express();
app.use('/proxy/', proxy('127.0.0.1:3020'));
var targetApp = express();
targetApp
.get('/', function (req, res) { res.sendStatus(211); })
.listen(3020);
request(app)
.get('/proxy/')
.expect(211)
.end(done);
});
});

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

var proxy = require('../');
var http = require('http');
var assert = require('assert');

@@ -43,2 +45,5 @@ describe('when skipToNextHandlerFilter is defined', function () {

app.use(function (req, res) {
assert(res.expressHttpProxy instanceof Object);
assert(res.expressHttpProxy.res instanceof http.IncomingMessage);
assert(res.expressHttpProxy.req instanceof Object);
res.sendStatus(200);

@@ -45,0 +50,0 @@ });

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

target.use('/headers', function(req, res) {
res.json({ headers: req.headers });
});
target.use(function(err, req, res, next) {

@@ -37,0 +41,0 @@ res.send(err);

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