From 049780528bc4e12e497e715a83e90db88ffed6dd Mon Sep 17 00:00:00 2001 From: Gustav Tiger Date: Wed, 29 Aug 2018 22:11:07 +0200 Subject: [PATCH] Bump http-proxy version to 1.17.0 (#261) The http-proxy was recently updated with many features and bug fixes. This commit brings in the latest version and updates the README.md file with new (and missing) options. --- README.md | 34 ++++++++++++++++++++++++++++++++++ package-lock.json | 37 ++++++++++++++++++++++++++++++++----- package.json | 2 +- 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d800c55..7e0d09a8 100644 --- a/README.md +++ b/README.md @@ -309,6 +309,7 @@ The following options are provided by the underlying [http-proxy](https://github * **option.ignorePath**: true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request (note: you will have to append / manually if required). * **option.localAddress** : Local interface string to bind for outgoing connections * **option.changeOrigin**: true/false, Default: false - changes the origin of the host header to the target URL +* **option.preserveHeaderKeyCase**: true/false, Default: false - specify whether you want to keep letter case of response header key * **option.auth** : Basic authentication i.e. 'user:password' to compute an Authorization header. * **option.hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects. * **option.autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false. @@ -325,8 +326,41 @@ The following options are provided by the underlying [http-proxy](https://github "*": "" } ``` +* **option.cookiePathRewrite**: rewrites path of `set-cookie` headers. Possible values: + * `false` (default): disable cookie rewriting + * String: new path, for example `cookiePathRewrite: "/newPath/"`. To remove the path, use `cookiePathRewrite: ""`. To set path to root use `cookiePathRewrite: "/"`. + * Object: mapping of paths to new paths, use `"*"` to match all paths. + For example, to keep one path unchanged, rewrite one path and remove other paths: + ``` + cookiePathRewrite: { + "/unchanged.path/": "/unchanged.path/", + "/old.path/": "/new.path/", + "*": "" + } + ``` * **option.headers**: object, adds [request headers](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields). (Example: `{host:'www.example.org'}`) * **option.proxyTimeout**: timeout (in millis) when proxy receives no response from target +* **option.timeout**: timeout (in millis) for incoming requests +* **option.followRedirects**: true/false, Default: false - specify whether you want to follow redirects +* **option.selfHandleResponse** true/false, if set to true, none of the webOutgoing passes are called and it's your responsibility to appropriately return the response by listening and acting on the `proxyRes` event +* **option.buffer**: stream of data to send as the request body. Maybe you have some middleware that consumes the request stream before proxying it on e.g. If you read the body of a request into a field called 'req.rawbody' you could restream this field in the buffer option: + + ``` + 'use strict'; + + const streamify = require('stream-array'); + const HttpProxy = require('http-proxy'); + const proxy = new HttpProxy(); + + module.exports = (req, res, next) => { + + proxy.web(req, res, { + target: 'http://localhost:4003/', + buffer: streamify(req.rawBody) + }, next); + + }; + ``` diff --git a/package-lock.json b/package-lock.json index 46cdaddc..50270533 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2337,7 +2337,8 @@ "eventemitter3": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-1.2.0.tgz", - "integrity": "sha1-HIaZHYFq0eUEdQ5zh0Ik7PO+xQg=" + "integrity": "sha1-HIaZHYFq0eUEdQ5zh0Ik7PO+xQg=", + "dev": true }, "expand-brackets": { "version": "2.1.4", @@ -2836,6 +2837,24 @@ "write": "0.2.1" } }, + "follow-redirects": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.4.1.tgz", + "integrity": "sha512-uxYePVPogtya1ktGnAAXOacnbIuRMB4dkvqeNz2qTtTQsuzSfbDolV+wMMKxAmCx0bLgAKLbBOkjItMbbkR1vg==", + "requires": { + "debug": "3.1.0" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + } + } + }, "for-in": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", @@ -4186,12 +4205,20 @@ } }, "http-proxy": { - "version": "1.16.2", - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.16.2.tgz", - "integrity": "sha1-Bt/ykpUr9k2+hHH6nfcwZtTzd0I=", + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.17.0.tgz", + "integrity": "sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==", "requires": { - "eventemitter3": "1.2.0", + "eventemitter3": "3.0.1", + "follow-redirects": "1.4.1", "requires-port": "1.0.0" + }, + "dependencies": { + "eventemitter3": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.0.1.tgz", + "integrity": "sha512-QOCPu979MMWX9XNlfRZoin+Wm+bK1SP7vv3NGUniYwuSJK/+cPA10blMaeRgzg31RvoSFk6FsCDVa4vNryBTGA==" + } } }, "http-signature": { diff --git a/package.json b/package.json index ce6ee4ff..f1271550 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "ws": "^5.0.0" }, "dependencies": { - "http-proxy": "^1.16.2", + "http-proxy": "^1.17.0", "is-glob": "^4.0.0", "lodash": "^4.17.5", "micromatch": "^3.1.9"