Skip to content

Commit e9e25ca

Browse files
docs(response-interceptor.md): add headers modification example (#724)
* Update response-interceptor.md An update to the responseInterceptor recipe to include modifying headers * docs: fixed issues with linting in the file
1 parent 2d6741a commit e9e25ca

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)