From 6f88caf6e46d84a809910c591e138250b333b39f Mon Sep 17 00:00:00 2001 From: Jon Hunter Date: Mon, 11 Sep 2017 13:31:13 +0100 Subject: [PATCH] Add detail about "buffer" option --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 64cbb4f..5971e5a 100644 --- a/README.md +++ b/README.md @@ -376,7 +376,24 @@ proxyServer.listen(8015); * **proxyTimeout**: timeout (in millis) for outgoing proxy requests * **timeout**: timeout (in millis) for incoming requests * **selfHandleRequest** true/false, if set to true, none of the webOutgoing passes are called and its your responsibility ro appropriately return the response by listening and acting on the `proxyRes` event +* **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); + + }; + ``` **NOTE:** `options.ws` and `options.ssl` are optional. `options.target` and `options.forward` cannot both be missing @@ -386,6 +403,7 @@ If you are using the `proxyServer.listen` method, the following options are also * **ssl**: object to be passed to https.createServer() * **ws**: true/false, if you want to proxy websockets + **[Back to top](#table-of-contents)** ### Listening for proxy events