-
Notifications
You must be signed in to change notification settings - Fork 872
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 [email protected]
or yarn add [email protected]
- 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
rohit-nair, krnlde, victor9000, csakaszamok, jaapspiering and 2 morejaapspiering, Emiya0306 and duck123ducker
Metadata
Metadata
Assignees
Labels
No labels