Skip to content

Commit 184aa4a

Browse files
authored
docs(response interceptor): align with nodejs default utf8 (chimurai#567)
1 parent 2831df9 commit 184aa4a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ const proxy = createProxyMiddleware({
527527
* Intercept response and replace 'Hello' with 'Goodbye'
528528
**/
529529
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
530-
const response = responseBuffer.toString('utf-8'); // convert buffer to string
530+
const response = responseBuffer.toString('utf8'); // convert buffer to string
531531
return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
532532
}),
533533
});

examples/response-interceptor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const jsonPlaceholderProxy = createProxyMiddleware({
5050
console.log(exchange);
5151

5252
// log original response
53-
// console.log(`[DEBUG] original response:\n${buffer.toString('utf-8')}`);
53+
// console.log(`[DEBUG] original response:\n${buffer.toString('utf8')}`);
5454

5555
// set response content-type
5656
res.setHeader('content-type', 'application/json; charset=utf-8');

recipes/response-interceptor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const proxy = createProxyMiddleware({
2424
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
2525
res.statusCode = 418; // set different response status code
2626

27-
const response = responseBuffer.toString('utf-8');
27+
const response = responseBuffer.toString('utf8');
2828
return response.replace('Hello', 'Teapot');
2929
}),
3030
});
@@ -45,7 +45,7 @@ const proxy = createProxyMiddleware({
4545
console.log(exchange); // [DEBUG] GET / -> http://www.example.com [200]
4646

4747
// log complete response
48-
const response = responseBuffer.toString('utf-8');
48+
const response = responseBuffer.toString('utf8');
4949
console.log(response); // log response body
5050

5151
return responseBuffer;
@@ -65,7 +65,7 @@ const proxy = createProxyMiddleware({
6565
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
6666
// detect json responses
6767
if (proxyRes.headers['content-type'] === 'application/json') {
68-
let data = JSON.parse(responseBuffer.toString('utf-8'));
68+
let data = JSON.parse(responseBuffer.toString('utf8'));
6969

7070
// manipulate JSON data here
7171
data = Object.assign({}, data, { extra: 'foo bar' });

0 commit comments

Comments
 (0)