Skip to content

Commit 1c5bd04

Browse files
authored
Merge branch 'master' into fix-request-body-update
2 parents 1cf524a + e9e25ca commit 1c5bd04

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

recipes/response-interceptor.md

+24
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,27 @@ const proxy = createProxyMiddleware({
128128

129129
// http://localhost:3000/wikipedia/en/7/7d/Lenna\_%28test_image%29.png
130130
```
131+
132+
## Manipulate response headers
133+
134+
```js
135+
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
136+
137+
const proxy = createProxyMiddleware({
138+
target: 'http://www.example.com',
139+
changeOrigin: true, // for vhosted sites
140+
141+
/**
142+
* IMPORTANT: avoid res.end being called automatically
143+
**/
144+
selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()
145+
146+
/**
147+
* Intercept response and remove the
148+
**/
149+
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
150+
res.removeHeader('content-security-policy'); // Remove the Content Security Policy header
151+
res.setHeader('HPM-Header', 'Intercepted by HPM'); // Set a new header and value
152+
}),
153+
});
154+
```

0 commit comments

Comments
 (0)