Skip to content

Commit 6f88caf

Browse files
jonhunter1977indexzero
authored andcommitted
Add detail about "buffer" option
1 parent d2f9db8 commit 6f88caf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,24 @@ proxyServer.listen(8015);
376376
* **proxyTimeout**: timeout (in millis) for outgoing proxy requests
377377
* **timeout**: timeout (in millis) for incoming requests
378378
* **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
379+
* **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:
379380
381+
```
382+
'use strict';
383+
384+
const streamify = require('stream-array');
385+
const HttpProxy = require('http-proxy');
386+
const proxy = new HttpProxy();
387+
388+
module.exports = (req, res, next) => {
389+
390+
proxy.web(req, res, {
391+
target: 'http://localhost:4003/',
392+
buffer: streamify(req.rawBody)
393+
}, next);
394+
395+
};
396+
```
380397
**NOTE:**
381398
`options.ws` and `options.ssl` are optional.
382399
`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
386403
* **ssl**: object to be passed to https.createServer()
387404
* **ws**: true/false, if you want to proxy websockets
388405
406+
389407
**[Back to top](#table-of-contents)**
390408
391409
### Listening for proxy events

0 commit comments

Comments
 (0)