Skip to content

Commit

Permalink
docs(response-interceptor.md): add headers modification example (#724)
Browse files Browse the repository at this point in the history
* Update response-interceptor.md

An update to the responseInterceptor recipe to include modifying headers

* docs: fixed issues with linting in the file
  • Loading branch information
stefanwright1988 committed Mar 10, 2022
1 parent 2d6741a commit e9e25ca
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions recipes/response-interceptor.md
Expand Up @@ -128,3 +128,27 @@ const proxy = createProxyMiddleware({

// http://localhost:3000/wikipedia/en/7/7d/Lenna\_%28test_image%29.png
```

## Manipulate response headers

```js
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');

const proxy = createProxyMiddleware({
target: 'http://www.example.com',
changeOrigin: true, // for vhosted sites

/**
* IMPORTANT: avoid res.end being called automatically
**/
selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()

/**
* Intercept response and remove the
**/
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
res.removeHeader('content-security-policy'); // Remove the Content Security Policy header
res.setHeader('HPM-Header', 'Intercepted by HPM'); // Set a new header and value
}),
});
```

0 comments on commit e9e25ca

Please sign in to comment.