Closed
Description
Add responseInterceptor
handler to easily intercept and manipulate responses. Responses compressed with brotli
, gzip
and deflate
are decompressed automatically.
install beta: npm install http-proxy-middleware@1.2.0-beta.2
or yarn add http-proxy-middleware@1.2.0-beta.2
- fixes [ Question ] How do you manipulate proxy response #97
- fixes Intercept and modify the response sent by the proxied server #469
- fixes Create modify-or-save-responses.md #355
TL;DR
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
const proxy = createProxyMiddleware({
/**
* IMPORTANT: avoid res.end being called automatically
**/
selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()
/**
* Intercept response and replace 'Hello' with 'Goodbye'
**/
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
const response = responseBuffer.toString('utf-8'); // convert buffer to string
return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
}),
});
documentation: https://github.com/chimurai/http-proxy-middleware/tree/response-interceptor#intercept-and-manipulate-responses
Metadata
Metadata
Assignees
Labels
No labels